refactor(stats): shrink and tidy WhichStats#3822
Merged
Merged
Conversation
The percentile list is set once from the CLI flag and never mutated afterward, so a heap-allocated owned String is overkill. Box<str> drops the unused capacity word, shrinking WhichStats from 40 to 32 bytes while remaining serde-transparent (no change to the on-disk .stats.csv.json cache format). Benchmarked on a 514 MB / 1M-row CSV with both `stats` and `stats --everything`; runtime is unchanged within measurement noise (this is a cleanup, not a perf win). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move use_weights above percentile_list so all 12 bool fields form a contiguous block with the variable-size Box<str> at the end. Source order has no runtime effect (WhichStats is repr(Rust) and the compiler already picks an optimal layout); this is purely a readability nit and mirrors the change in Args::which_stats so the constructor matches the struct definition. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
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.
Summary
WhichStats::percentile_listfromStringtoBox<str>. The field is set once from the CLI flag and never mutated, so the unused capacity word is wasted. ShrinksWhichStatsfrom 40 → 32 bytes and is serde-transparent (no change to the on-disk<file>.stats.csv.jsoncache format; reading old caches still works).use_weightsabovepercentile_listso all 12 bool fields form a contiguous block with the variable-sizeBox<str>at the end. Source order has no runtime effect (WhichStatsisrepr(Rust)); purely a readability nit.Performance note
This is not a perf win — framed as
refactor/stylefor that reason. Benchmarked on a 514 MB / 1M-rowNYC_311_SR_2010-2020-sample-1M.csv(M4 Max, 10 runs each,--forceto bypass cache):statsstats --everythingBoth deltas are inside measurement noise. The theoretical cache-line argument (sub-cache-line spillover from
which: WhichStatsintoStats' second cache line) doesn't materialize, likely becauseStatsis#[repr(C, align(64))]and the 8 saved bytes get absorbed into existing tail padding, plus the bool reads are extremely well-predicted per column.Test plan
cargo build --locked --bin qsv -F all_featurescargo clippy -F all_features --bin qsv -- -D warningscargo t stats -F all_features— all 728 stats tests pass🤖 Generated with Claude Code