Skip to content

perf(progress): fast-path log_if_needed via cached next threshold - #345

Merged
nh13 merged 1 commit into
mainfrom
nh/progress-next-threshold
May 21, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/progress-next-threshold

Conversation

@nh13

@nh13 nh13 commented May 16, 2026

Copy link
Copy Markdown
Member

Stacked on #344.

Summary

  • Replace the divide-by-interval check in ProgressTracker::log_if_needed with a comparison against a cached next_threshold, saving ~30-60 cycles per call.
  • Mark the milestone-crossing branch #[cold] and re-read next_threshold under the EMA mutex so concurrent crossings can't double-log.

Why

log_if_needed(1) is called once per record on hot BAM paths. On a 16-thread sort at ~32 M calls/s this branch shows up as ~1 % of total CPU in profiles. The thresholds form a fixed arithmetic sequence, so caching the next one removes the division entirely on the predicted-not-taken fast path.

Test plan

  • cargo ci-test
  • cargo ci-fmt && cargo ci-lint
  • Spot-check a sort run logs progress at expected intervals

@nh13
nh13 temporarily deployed to github-actions May 16, 2026 04:06 — with GitHub Actions Inactive
@codecov

codecov Bot commented May 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.97%. Comparing base (c781d53) to head (5fb46c8).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #345   +/-   ##
=======================================
  Coverage   90.97%   90.97%           
=======================================
  Files          78       78           
  Lines       51017    51017           
=======================================
+ Hits        46412    46413    +1     
+ Misses       4605     4604    -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nh13

nh13 commented May 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 16, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 47149871-57ab-4b6d-a22e-cd42c0c34d55

📥 Commits

Reviewing files that changed from the base of the PR and between 9ed3d21 and 5fb46c8.

📒 Files selected for processing (1)
  • crates/fgumi-bam-io/src/progress.rs

📝 Walkthrough

Hidden review stack artifact:

Walkthrough

ProgressTracker adds an atomic next_threshold to track the next milestone boundary and avoid per-call division. with_interval() stores the configured interval into that atomic. log_if_needed() performs an atomic fetch-and-add and quickly returns unless new_count reaches next_threshold; when reached it calls a slow-path that acquires the EMA mutex, re-checks the threshold, updates EMA if total is set, logs each crossed milestone with percentage/ETA, advances the threshold, and returns whether the call landed on the last logged milestone.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately describes the main optimization: replacing a divide operation with a cached threshold comparison for performance improvement.
Description check ✅ Passed Description clearly explains the optimization, motivation, and testing approach, directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nh/progress-next-threshold

Comment @coderabbitai help to get the list of available commands and usage tips.

@nh13

nh13 commented May 16, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 16, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 force-pushed the nh/perf-followups branch 2 times, most recently from 18ba353 to 77009a9 Compare May 18, 2026 15:42
Base automatically changed from nh/perf-followups to main May 18, 2026 15:46
… path

The fast path now compares `count` against a cached `next_threshold`
instead of dividing by `interval`, saving ~30-60 cycles per call. At
~32 M `log_if_needed(1)` calls/s on a 16-thread sort, this is ~1 % of
total CPU in profiles. Marked the slow path `#[cold]` and re-reads
`next_threshold` under the EMA mutex so concurrent crossings can't
double-log.
@nh13
nh13 force-pushed the nh/progress-next-threshold branch from 9ed3d21 to 5fb46c8 Compare May 18, 2026 15:56
@nh13
nh13 temporarily deployed to github-actions May 18, 2026 15:57 — with GitHub Actions Inactive
@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai resume

@nh13

nh13 commented May 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Reviews resumed.

@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@nh13
nh13 merged commit 6b2f3f6 into main May 21, 2026
10 checks passed
@nh13
nh13 deleted the nh/progress-next-threshold branch May 21, 2026 19:42
@nh13 nh13 mentioned this pull request May 21, 2026

This branch was previously deployed

1 inactive deployment
github-actions — 5fb46c8b Deployed May 18, 2026 by nh13 via coverage #1452
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