Skip to content

docs(reorder-buffer): correct insert complexity and add micro-bench - #265

Merged
nh13 merged 1 commit into
mainfrom
nh/reorder-buffer-doc-bench
Apr 15, 2026
Merged

nh13 merged 1 commit into
mainfrom
nh/reorder-buffer-doc-bench

Conversation

@nh13

@nh13 nh13 commented Apr 14, 2026

Copy link
Copy Markdown
Member

Summary

  • Fix a misleading complexity claim in ReorderBuffer's docstring. It said "O(1) insert and pop operations," but insert_with_size runs a while self.buffer.len() <= index { push_back(None) } loop, so insert is O(gap) when a sequence number arrives ahead of the current buffer end. Pop remains O(1). The docstring now states the actual contract.
  • Add a criterion micro-bench at benches/reorder_buffer.rs covering four realistic insert patterns — purely in-order (k=0) and leading-gap (k=1, 8, 64) — over a 256-insert fill+drain cycle per iteration. Bench target registered in Cargo.toml mirroring the existing core_functions block with harness = false.

The bench exists so future data-structure swaps (BTreeMap, BinaryHeap, fixed-capacity ring buffer) can be measured honestly against the current sparse-VecDeque behavior, including the O(gap) path the corrected doc now advertises.

No functional change; no API change.

Test plan

  • cargo build --release --bench reorder_buffer
  • cargo ci-fmt
  • cargo ci-lint
  • cargo bench --bench reorder_buffer -- --test
  • Reviewer: spot-check bench output is stable across runs

@nh13
nh13 temporarily deployed to github-actions April 14, 2026 21:49 — with GitHub Actions Inactive
@nh13
nh13 marked this pull request as ready for review April 14, 2026 21:50
@coderabbitai

coderabbitai Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Warning

Rate limit exceeded

@nh13 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 51 minutes and 25 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 51 minutes and 25 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: eddbb366-b9f4-4655-823a-477c08906775

📥 Commits

Reviewing files that changed from the base of the PR and between 072f8c7 and fb77c7a.

📒 Files selected for processing (3)
  • Cargo.toml
  • benches/reorder_buffer.rs
  • src/lib/reorder_buffer.rs
📝 Walkthrough

Walkthrough

This change adds a Criterion benchmark for the ReorderBuffer::insert_with_size operation. A new benchmark target is configured in Cargo.toml, and the corresponding benchmark file measures insertion performance across two workload patterns: in-order insertions and insertions with leading gaps of varying sizes (k=1, 8, 64). The benchmark performs sequential inserts followed by drains to measure throughput. Documentation in the reorder buffer module is updated to clarify complexity characteristics: pop operations are O(1) via VecDeque, while insert operations are O(1) for in-order sequences but O(gap) when creating sentinel entries for missing slots.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed Title clearly summarizes the main changes: correcting documentation complexity and adding a benchmark for ReorderBuffer insert operations.
Description check ✅ Passed Description directly relates to the changeset, explaining the docstring fix and benchmark additions with clear rationale and test plan.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch nh/reorder-buffer-doc-bench

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@codecov

codecov Bot commented Apr 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.87%. Comparing base (25ede93) to head (fb77c7a).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #265      +/-   ##
==========================================
+ Coverage   89.84%   89.87%   +0.03%     
==========================================
  Files         120      120              
  Lines       61359    61416      +57     
==========================================
+ Hits        55127    55197      +70     
+ Misses       6232     6219      -13     

☔ 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 added the enhancement New feature or request label Apr 14, 2026
@nh13

nh13 commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

2 similar comments
@nh13

nh13 commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@nh13

nh13 commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 15, 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 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@benches/reorder_buffer.rs`:
- Around line 53-70: The benchmark currently computes chunks = batch_size /
chunk which drops the remainder and understates per-batch work; change the loop
to process the full batch_size by computing total_chunks = (batch_size + chunk -
1) / chunk (or loop while processed < batch_size), and for each iteration
compute this_chunk = min(chunk, remaining) so you only insert that many slots:
insert the far slot only if this_chunk > 0, then insert min(k, this_chunk - 1)
near slots (use buffer.insert_with_size), drain with
buffer.try_pop_next_with_size as before, and advance base by this_chunk instead
of always chunk; update references: chunk, batch_size, k, base,
buffer.insert_with_size, buffer.try_pop_next_with_size.
- Line 13: Add a file-level deny for unsafe code in benches/reorder_buffer.rs by
adding the attribute #![deny(unsafe_code)] at the top of the file (adjacent to
or replacing the existing #![allow(clippy::cast_possible_truncation)] line) so
this bench target is compiled with the crate policy; ensure the deny attribute
appears before any module items to apply at file scope.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1d0c4a08-dff5-4c67-bdca-46f528feb668

📥 Commits

Reviewing files that changed from the base of the PR and between 25ede93 and 072f8c7.

📒 Files selected for processing (3)
  • Cargo.toml
  • benches/reorder_buffer.rs
  • src/lib/reorder_buffer.rs

Comment thread benches/reorder_buffer.rs
Comment thread benches/reorder_buffer.rs
The `ReorderBuffer` docstring claimed "O(1) insert and pop operations",
but `insert_with_size` runs a `while self.buffer.len() <= index { push_back(None) }`
loop when a sequence number arrives ahead of the current buffer end, so
insert is O(gap) in the general case (O(1) only for in-order arrivals).
Pop is genuinely O(1). Rewrite the doc line to say so.

Add a criterion micro-bench `benches/reorder_buffer.rs` that measures
`insert_with_size` across four realistic patterns — purely in-order
(k=0) and leading-gap (k=1, 8, 64) — over a 256-insert fill+drain
cycle. The bench exists so future data-structure swaps (BTreeMap,
BinaryHeap, ring buffer) can be measured honestly against the current
sparse-VecDeque behavior, including the O(gap) insert path that the
fixed doc now advertises.
@nh13
nh13 force-pushed the nh/reorder-buffer-doc-bench branch from 072f8c7 to fb77c7a Compare April 15, 2026 19:58
@nh13
nh13 temporarily deployed to github-actions April 15, 2026 19:58 — with GitHub Actions Inactive
@nh13

nh13 commented Apr 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 15, 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 Apr 15, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Apr 15, 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 8be8959 into main Apr 15, 2026
9 checks passed
@nh13
nh13 deleted the nh/reorder-buffer-doc-bench branch April 15, 2026 23:57
@nh13 nh13 mentioned this pull request Apr 15, 2026
nh13 added a commit that referenced this pull request Apr 17, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 20, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 20, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 20, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 20, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 20, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 21, 2026
… remaining 48-commit work

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
nh13 added a commit that referenced this pull request Apr 21, 2026
… remaining 48-commit work (#296)

The final PR in the stacked series closes the full delta against the
48-commit backup. In addition to the original scope (vendored bam_codec
deletion + simulate migration), this amends to include:

- Missing new files: sort/keys.rs, 4 raw-bam bench files
- compare/bams.rs RawRecord migration
- codec_caller.rs cascade simplification
- group/filter/correct/extract/clip/bam_io.rs simplifications
- overlapping.rs raw-only API
- Test suite updates for test_compare_bams, test_group_command,
  test_e2e_regression
- Doc touch-ups in best-practices/performance-tuning

Verified: tree matches backup except for 6 main-only files
(prefetch_reader, os_hints, test_async_reader, template_coordinate,
and two benches) that came from main PRs #258/#261/#265/#270/#282
merged after our branch point.

Part 8 of 8 in the series closing #272. Stacks on #295.
@nh13 nh13 mentioned this pull request Apr 22, 2026

This branch was previously deployed

1 inactive deployment
github-actions — fb77c7a9 Deployed Apr 15, 2026 by nh13 via coverage #1139
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant