feat: implement stable hash for ProjectModelV1 to improve cache consistency#4094
feat: implement stable hash for ProjectModelV1 to improve cache consistency#4094Hofer-Julian merged 8 commits intoprefix-dev:mainfrom
Conversation
Hofer-Julian
left a comment
There was a problem hiding this comment.
One comment, then it's ready to go 🚀
| impl Hash for TargetSelectorV1 { | ||
| fn hash<H: std::hash::Hasher>(&self, state: &mut H) { | ||
| match self { | ||
| TargetSelectorV1::Unix => 0u8.hash(state), | ||
| TargetSelectorV1::Linux => 1u8.hash(state), | ||
| TargetSelectorV1::Win => 2u8.hash(state), | ||
| TargetSelectorV1::MacOs => 3u8.hash(state), | ||
| TargetSelectorV1::Platform(p) => { | ||
| 4u8.hash(state); | ||
| p.hash(state); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I think we should add doc comments to all hash functions explaining that the goal is to keep the hash as stable as possible
|
Thanks for the feedback! I've added comprehensive doc comments to all Hash implementations explaining the stability goals:
Each implementation now has clear documentation about why we use custom Hash traits and how they contribute to hash stability. Ready for another look! 🚀 |
|
I dont think we have to mark this as breaking. This will only break peoples workflow when they use locked source dependencies (which are still in preview). But would be good to add a note to the release notes. |
|
@Hofer-Julian I added a PR to the test-suite to update the hashes there: prefix-dev/pixi-build-testsuite#21 In which order do you want to merge things? |
Summary
Implements custom Hash traits for ProjectModelV1 and all nested types that skip default/empty values in hash calculation for better stability. This allows adding new optional fields without breaking existing hashes, improving cache consistency and reducing unnecessary rebuilds.
Technical Details
#[derive(Hash)]from all ProjectModelV1 typesNonevalues in Option fields*.local.*filesBefore/After Behavior
Before: Adding any new field would change the hash, breaking cache invalidation
After: Adding new optional fields with default values doesn't affect hash
Testing
Added 4 comprehensive tests covering:
Benefits