Skip to content

perf(moarstats): hint rare branches with core::hint::cold_path()#3823

Merged
jqnatividad merged 2 commits intomasterfrom
moarstats-cold-path
May 5, 2026
Merged

perf(moarstats): hint rare branches with core::hint::cold_path()#3823
jqnatividad merged 2 commits intomasterfrom
moarstats-cold-path

Conversation

@jqnatividad
Copy link
Copy Markdown
Collaborator

Summary

  • Adds core::hint::cold_path() hints to exceptional branches inside the per-record hot loops of count_chunk_outliers and compute_chunk_bivariate, matching the pattern already used in stats.rs, frequency.rs, and validate.rs.
  • Hinted branches: UTF-8 decode failures on CSV byte cells (virtually always valid UTF-8) and chunk_stats.get_mut safety guards already paired with debug_assert!(false, ...).
  • Deliberately skipped: leaf compute_* finalizer helpers (called O(columns), not in a tight loop), is_empty() checks in parse_float_opt* / parse_date_to_days (empty cells are common in real CSVs), and the outlier-bucket if/else chain (whole purpose of that loop is counting outliers — can't assume "normal" is hot).

Test plan

  • cargo build --locked --bin qsv -F all_features — clean
  • cargo test moarstats -F all_features — 88 passed, 0 failed
  • cargo clippy --bin qsv -F all_features -- -D warnings — clean

🤖 Generated with Claude Code

Mark exceptional branches inside the per-record hot loops of
`count_chunk_outliers` and `compute_chunk_bivariate` as cold so the
compiler can keep the common path tight:

- UTF-8 decode failures on byte cells (CSV cells are virtually always
  valid UTF-8)
- `chunk_stats.get_mut` "this can't happen" safety guards already
  paired with `debug_assert!(false, ...)`

Leaf `compute_*` finalizer helpers, `is_empty()` checks in the parsers,
and the outlier-bucket if/else chain were intentionally not hinted —
they are not on a tight inner loop or their branch frequency depends on
the dataset.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented May 5, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Address roborev review #1956 (Low): move `use core::hint::cold_path;`
to the top of the import block, matching the convention in
`src/cmd/stats.rs`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jqnatividad jqnatividad merged commit 7d611f0 into master May 5, 2026
16 of 17 checks passed
@jqnatividad jqnatividad deleted the moarstats-cold-path branch May 5, 2026 13:32
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.

1 participant