Repository navigation
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
CodeGenContext's internal bookkeeping (package/message name deconfliction, doc-comment lookup, oneof/message indexing) used std::HashMap, which defaults to SipHash. Profiling a multi-thousand-file codegen run showed Hasher::write/hash_one (SipHash) as the single largest sampled cost bucket, ahead of any actual codegen logic. This data only ever comes from trusted, locally-generated .proto descriptors, never attacker-controlled input, so SipHash's hash-flooding resistance buys nothing here. Swap context.rs and comments.rs's maps to foldhash (already resolved transitively via hashbrown, so this adds no new third-party code to the tree, just a direct dependency on what's already there). oneof.rs was tried too but reverted: its map types leak through public signatures in message.rs/view.rs/lazy_view.rs, too broad a blast radius for what should be a purely internal, output-invariant change. Verified output-invariant: full hash-diff of a real 2895-crate generation run, before and after, is byte-for-byte identical. All 619 existing tests pass.
th0114nd
force-pushed
the
th0114nd/fast-hasher
branch
from
August 30, 2026 15:51
fe4244b to
c42c821
Compare
Contributor
Author
|
Closing this — on reflection, a ~3-7% wall-clock improvement (verified via interleaved trials after an earlier noisy measurement) doesn't clearly justify separate review attention on its own, especially alongside #399's ~2x improvement, which deserves the focus. Not pursuing further for now; may revisit later if it's ever bundled with something else that needs the same review pass. Thanks for reading this far regardless — no action needed. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #396.
What this does
CodeGenContext's internal bookkeeping (context.rs's naming/deconfliction maps,comments.rs's doc-comment lookup) usedstd::collections::HashMap, which defaults to SipHash. This data only ever comes from trusted, locally-generated.protodescriptors — never attacker-controlled input — so SipHash's hash-flooding resistance buys nothing here, and profiling showed it as the single largest sampled cost bucket on a large multi-thousand-file codegen run (see #396 for the numbers).Swaps
context.rsandcomments.rs's internal maps tofoldhashvia a smallhash.rstype alias (FxHashMap).foldhashis already resolved transitively viahashbrown, so this is a direct dependency on something already in the tree.oneof.rs's maps were tried too but reverted: their types leak through public signatures inmessage.rs/view.rs/lazy_view.rs, too broad a blast radius for what should be a purely internal, output-invariant change. Left asstd::HashMap.One field (
CodeGenContext::field_renames) staysstd::collections::HashMapexplicitly — it's populated fromfield_names::plan_field_names, which isn't touched by this change, so its type has to match.Testing
buffa-codegentests pass unmodified (cargo test -p buffa-codegen --lib).cargo fmt,cargo clippy --workspace --all-targets -- -D warnings, andcargo doc --all-featuresall clean.