Skip to content

chore: Replace fxhash with ahash#1674

Merged
Hofer-Julian merged 17 commits intoconda:mainfrom
haecker-felix:fxhash
Oct 27, 2025
Merged

chore: Replace fxhash with ahash#1674
Hofer-Julian merged 17 commits intoconda:mainfrom
haecker-felix:fxhash

Conversation

@haecker-felix
Copy link
Copy Markdown
Contributor

The fxhash crate is no longer maintained. See https://rustsec.org/advisories/RUSTSEC-2025-0057.html

The rustc-hash is pretty much a drop-in replacement for fxhash. It has the same type names, but uses a different hashing algorithm under the hood:

The original hash algorithm provided by this crate was one taken from Firefox, hence the hasher it provides is called FxHasher. This name is kept for backwards compatibility, but the underlying hash has since been replaced. The current design for the hasher is a polynomial hash finished with a single bit rotation, together with a wyhash-inspired compression function for strings/slices, both designed by Orson Peters.

@baszalmstra
Copy link
Copy Markdown
Collaborator

If we are switching the hash algorithm we could also use ahash instead!

@haecker-felix haecker-felix changed the title chore: Replace fxhash with rustc-hash chore: Replace fxhash with ahash Sep 10, 2025
@haecker-felix haecker-felix force-pushed the fxhash branch 2 times, most recently from fe84a68 to 3ec8a94 Compare September 29, 2025 07:22
@haecker-felix
Copy link
Copy Markdown
Contributor Author

Now using the standard library’s HashMap and HashSet with ahash::RandomState.

Unlike FxHashMap and FxHashSet, the standard library versions no longer guarantee deterministic ordering of elements. I had to update some tests to account for this.

Not sure whether there may be other unintended side effects that the tests haven’t caught...

let mut visited = HashSet::default();

let mut package_names: Vec<_> = packages.keys().collect();
package_names.sort();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing I had to change because of the no longer deterministic ordering of the HashSet.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer we use IndexMap for these types to make sure they are deterministic instead of reordering which is more expensive.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FAIL [   0.040s] rattler_conda_types repo_data::topological_sort::tests::test_topological_sort::case_6
  stdout ───

    running 1 test
    test repo_data::topological_sort::tests::test_topological_sort::case_6 ... FAILED

    failures:

    failures:
        repo_data::topological_sort::tests::test_topological_sort::case_6

    test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 324 filtered out; finished in 0.03s
    
  stderr ───

    thread 'repo_data::topological_sort::tests::test_topological_sort::case_6' panicked at crates/rattler_conda_types/src/repo_data/topological_sort.rs:292:21:
    attempting to install panel (package 336 of 339) but dependency holoviews is not yet installed
    note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

@baszalmstra Even with IndexMap / IndexSet that particular test keeps failing if I don't sort the package names manually.

Could it be possible, that there's a bug which didn't get triggered with FxHashMap as it had a different random ordering - but what happened to be accidentally the correct order for the test to be successful?

@haecker-felix haecker-felix force-pushed the fxhash branch 2 times, most recently from 62ad0b0 to 65e06a6 Compare October 1, 2025 07:37
let mut visited = HashSet::default();

let mut package_names: Vec<_> = packages.keys().collect();
package_names.sort();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer we use IndexMap for these types to make sure they are deterministic instead of reordering which is more expensive.

@Hofer-Julian
Copy link
Copy Markdown
Collaborator

@baszalmstra I think it would be good if you could quickly glance at Felix' comment

@haecker-felix could you please solve the merge conflicts?

@haecker-felix
Copy link
Copy Markdown
Contributor Author

Rebased, merge conflicts resolved, and tests are passing now (windows test is an unrelated network error, should be fine when running again).

Looks like my issue in #1674 (comment) has been resolved by another change through rebasing.

Copy link
Copy Markdown
Collaborator

@Hofer-Julian Hofer-Julian left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Felix ✨

@Hofer-Julian Hofer-Julian merged commit c41541f into conda:main Oct 27, 2025
19 checks passed
@github-actions github-actions bot mentioned this pull request Oct 27, 2025
@baszalmstra
Copy link
Copy Markdown
Collaborator

Ah Im sorry I didnt didnt find the time to properly comment here. I was still noodling what was bothering me and why we now sometimes need to resort the entries.

The current PR changes the functionality of the library in unexpected way, as fields are no longer sorted before serialization. I think we should add back the serialize_with code to ensure that when writing the repodata files they are properly sorted.

@baszalmstra
Copy link
Copy Markdown
Collaborator

I think we should fix that before we release because it might break repodata indexing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants