Repository navigation
ci(ratchet): forbid std SipHash collections in hot-path modules (#1237) - #1364
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
📊 Benchmark Results
vs main branch (2026-06-15)
What do these numbers mean?
|
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a new CI “ratchet” to prevent performance regressions by forbidding std::collections::HashMap/HashSet (SipHash-backed) inside explicitly marked hot-path Rust modules, reinforcing the workspace’s FxHasher adoption.
Changes:
- Introduces
scripts/check-hot-path-collections.shand wires it into CI as a dedicated “Hot-path Collections” job. - Adds
// ratchet: fxhash-onlymarkers to selected hot-path modules to opt them into the check. - Converts a hot-path dedup set in booking from
std::collections::HashSettorustc_hash::FxHashSet.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
scripts/check-hot-path-collections.sh |
New grep-based ratchet script to scan marked modules for forbidden std collections. |
.github/workflows/ci.yml |
Adds a CI job to run the new ratchet script on PRs that should build. |
crates/rustledger-booking/src/book.rs |
Switches a local dedup set to FxHashSet and opts the module into the ratchet. |
crates/rustledger-core/src/inventory/mod.rs |
Opts this hot-path module into the ratchet via marker comment. |
crates/rustledger-loader/src/process.rs |
Opts this hot-path module into the ratchet via marker comment. |
crates/rustledger-query/src/executor/types.rs |
Opts this hot-path module into the ratchet via marker comment. |
crates/rustledger-validate/src/validators/balance.rs |
Opts this hot-path module into the ratchet via marker comment. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Contributor
✅ Compatibility Test Results
What's tested
Full results available in workflow artifacts |
Second of the #1237 ratchets, again as a grep ratchet (no nightly toolchain), using the marker-based opt-in pattern of `check-unsafe-invariant.sh`. FxHashMap/FxHashSet were adopted on hot paths in #1076 because std's SipHash default is much slower for the small-int/short-string keys these paths use. Nothing prevented a new `std::collections::HashMap` from regressing that. - `scripts/check-hot-path-collections.sh`: finds files marked `// ratchet: fxhash-only`, and fails if their non-test code uses `std::collections::HashMap`/`HashSet`. Excludes `#[cfg(test)]` modules and leaves `BTreeMap` (deterministic, sorted) untouched. Escape hatch: `// ratchet-allow: std-collections <reason>`. Verified it passes clean, catches a real (non-test) violation in a marked file, and ignores both test modules and unmarked files. - "Hot-path Collections" CI job (anchored after plugin-test-quality to avoid colliding with the sync-primitives job in #1363). - Marked five genuinely-hot, already-clean modules: booking `book.rs`, core `inventory/mod.rs`, loader `process.rs` (the booking pass), validate `balance.rs`, query `executor/types.rs`. - Converted the one std collection in a hot path — `book.rs`'s local `booked_indices` dedup set — from `std::collections::HashSet` to `FxHashSet` (drop-in: insert/contains/into_iter only). Modules that use std maps deliberately (e.g. query `aggregation.rs`'s GROUP BY map with its explicit `key_order`, and the `ShiftSpans` trait impl for `HashMap<_,_,S>`) are simply left unmarked; the ratchet is opt-in and extensible. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deep-review fixes: - BUG (toothless ratchet): the `hot-path-collections` job was not in the `build` aggregator's `needs` list or its `results` string, so a red ratchet did NOT block merge (`build` is the only required check). Added it to both. - Harden the test-module stripper: it stopped at the FIRST `#[cfg(test)]`, so a test-only `use`/`fn` near the top of a marked file would silently disable scanning of all real code below it. Now it only truncates at the trailing `#[cfg(test)] mod`, preserving scanning of non-test code while still ignoring the test module. Verified both behaviors. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Review nit on the FxHashSet conversion: `FxHashSet::default()` dropped the `with_capacity(txn.postings.len())` preallocation the std version had — a (small) rehash/growth regression in a hot path, ironic for a hot-path ratchet PR. Restored via `with_capacity_and_hasher`. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
robcohen
force-pushed
the
chore/1237-hot-path-collections
branch
from
June 15, 2026 09:17
5e459af to
2926be6
Compare
robcohen
enabled auto-merge (rebase)
June 15, 2026 09:17
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.
What
Second of the #1237 static-analysis ratchets: forbid std SipHash
HashMap/HashSetin hot-path modules, so the FxHasher adoption (#1076) can't silently regress.Like #1363, this is a grep ratchet (no nightly toolchain), using the marker-based opt-in pattern of
check-unsafe-invariant.sh.How it works
A module opts in with a marker near the top:
// ratchet: fxhash-onlyscripts/check-hot-path-collections.shfinds every marked file and fails if its non-test code usesstd::collections::HashMap/HashSet. It excludes#[cfg(test)]modules and leavesBTreeMap(deterministic/sorted) alone. Escape hatch:// ratchet-allow: std-collections <reason>.Verified: passes clean, catches a real (non-test) violation injected into a marked file, and correctly ignores both test modules and unmarked files.
Changes
scripts/check-hot-path-collections.sh+ aHot-path CollectionsCI job (anchored afterplugin-test-qualityto avoid colliding with ci(ratchet): forbid std::sync Mutex/RwLock in library code (#1237) #1363'ssync-primitivesinsertion).book.rs, coreinventory/mod.rs, loaderprocess.rs(the booking pass), validatebalance.rs, queryexecutor/types.rs.book.rs's localbooked_indicesdedup set — fromstd::collections::HashSettoFxHashSet(drop-in: onlyinsert/contains/into_iter).Modules that use std maps deliberately are left unmarked: query
aggregation.rs(GROUP BY map with an explicitkey_orderfor determinism) and theShiftSpanstrait impl forHashMap<_, _, S>. The ratchet is opt-in and extensible.Test plan
nix develop --command cargo test -p rustledger-booking— passesnix develop --command cargo clippy -p rustledger-booking -p rustledger-core -p rustledger-query -p rustledger-validate -p rustledger-loader --all-features --all-targets -- -D warnings— clean./scripts/check-hot-path-collections.sh— passes; injected violation rejected; unmarked/test usages ignoredPart of #1237. Independent of #1363 (different script + CI anchor; only
book.rsoverlaps, in disjoint regions).