Skip to content

chore: align number hash algorithm with webpack #10643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nilptr
Copy link
Contributor

@nilptr nilptr commented Jun 11, 2025

Summary

close #10614

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copy link

netlify bot commented Jun 11, 2025

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 2341d79
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/684a2fc3f921560008ebfb10

Copy link

codspeed-hq bot commented Jun 11, 2025

CodSpeed Performance Report

Merging #10643 will not alter performance

Comparing nilptr:nilptr/chore/align-number-hash-algorithm-with-webpack (2341d79) with main (df2f7cc)

Summary

✅ 12 untouched benchmarks

chore: add long string test cases
@CPunisher
Copy link
Contributor

🤔 Is this a breaking change cc @hardfist

let mut hash = FNV_OFFSET_64;

for code_unit in s.encode_utf16() {
hash ^= code_unit as u64;
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don’t have a strong preference between using the original fnv or the webpack variant. I just assumed the issue was meant to follow webpack’s changes and stay consistent with it — which would also provide a useful reference point for validation.

If your team concludes that the original version is better, just let me know — I can update the code along with the snapshots and test cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

I suggestion using original fnv, which avoids the overhead of encode utf16

}

pub fn get_number_hash(s: &str, range: usize) -> usize {
if range < FNV_64_THRESHOLD {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think webpack's choice here doesn't make sense, the performance advantage between 32bit fnv and 64bit fnv doesn't correspond to input length, but cpu arch.

I suggestion just using 64bit fnv1a.

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.

[Bug]: get_number_hash add with overflow in 32bit arch
3 participants