Skip to content

perf: gallop the backward trace upper bound from lower - #22

Merged
nh13 merged 1 commit into
mainfrom
feat/v0.2-gallop
Jun 10, 2026
Merged

perf: gallop the backward trace upper bound from lower#22
nh13 merged 1 commit into
mainfrom
feat/v0.2-gallop

Conversation

@nh13

@nh13 nh13 commented Jun 8, 2026

Copy link
Copy Markdown

PR #9 of the v0.2 stack (carries 8cbee1f). Base is feat/v0.2-prefetch (#21).

Gallops the backward trace upper bound up from the lower bound instead of a full-range search. Pure perf — byte-identical (the backward-spectrum oracle proptests pass unchanged). Clean cherry-pick onto #8.

Green-pass: build / clippy -D warnings / nightly fmt / cargo test --workspace all ✅ (162 lib + all FFI; only Plan-3 deferrals ignored).

Summary by CodeRabbit

  • Refactor
    • Internal reorganization to centralize and simplify a core search loop, improving maintainability and reducing duplicated logic.
    • No public API or behavior changes; end-user experience remains unchanged.

@coderabbitai

coderabbitai Bot commented Jun 8, 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: ef7689e4-aa86-4f32-a4c1-a15cc0e61577

📥 Commits

Reviewing files that changed from the base of the PR and between 89fa2e5 and 7c8ae2a.

📒 Files selected for processing (1)
  • prmi/src/index/spectrum.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • prmi/src/index/spectrum.rs

📝 Walkthrough

Walkthrough

This PR extracts the per-step SA-interval location from backward_spectrum_inner_into into backward_locate_step, which recomputes per-step 32-mer keys, derives a model-seeded hint window (or uses seed_override), performs two seeded boundary searches, and returns the located [lower, upper) interval or None. The main loop now calls this helper and exits on None.

Changes

SA Interval Location Refactoring

Layer / File(s) Summary
SA interval location helper
prmi/src/index/spectrum.rs
New backward_locate_step function encapsulates 32-mer key recomputation, hint window derivation from model prediction or seed override, and two exponential-from-hint boundary searches to locate the SA interval [lower, upper), returning None if empty.
Left-extension loop integration
prmi/src/index/spectrum.rs
backward_spectrum_inner_into refactored to form per-step p_slice and delegate interval computation to backward_locate_step, breaking the loop on None. Prior inline key derivation, window launch, and boundary search logic removed from loop body.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • fg-labs/prmi#21: Modifies find_boundary/probe loops to add SA-entry prefetching; touches the same backward boundary-search control path used by the new helper.

Poem

I nibble keys by lantern light,
Recompute 32-mers through the night,
Seeded hints and boundaries hop,
The loop steps left until it stops,
A rabbit hums — the index sings bright. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'perf: gallop the backward trace upper bound from lower' directly describes the core performance optimization in the changeset—switching to a gallop search strategy for the upper bound starting from the lower bound instead of full-range search.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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

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.

@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from a87d557 to 8d4efbf Compare June 8, 2026 04:15
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from c55fd44 to e69c7aa Compare June 8, 2026 04:16
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 8d4efbf to 5cf77bc Compare June 8, 2026 18:43
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from e69c7aa to 97a3d91 Compare June 8, 2026 18:44
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 5cf77bc to 2dff648 Compare June 8, 2026 21:12
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from 97a3d91 to aee9e6e Compare June 8, 2026 21:13
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 2dff648 to 82270b3 Compare June 8, 2026 22:45
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from aee9e6e to a6f30dc Compare June 8, 2026 22:45
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 82270b3 to fb058e1 Compare June 9, 2026 15:52
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from a6f30dc to 65a0e07 Compare June 9, 2026 15:53
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from fb058e1 to 8b38e55 Compare June 9, 2026 19:55
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from 65a0e07 to f17af9a Compare June 9, 2026 19:56
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 8b38e55 to 0d0b4d6 Compare June 10, 2026 00:20
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from f17af9a to f4b3e03 Compare June 10, 2026 00:21
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 0d0b4d6 to 4695361 Compare June 10, 2026 02:25
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from f4b3e03 to 399c6e1 Compare June 10, 2026 02:26
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 4695361 to 4c278fc Compare June 10, 2026 03:41
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from 399c6e1 to f2f09d1 Compare June 10, 2026 03:42
@nh13
nh13 force-pushed the feat/v0.2-prefetch branch from 4c278fc to 16f99ff Compare June 10, 2026 16:42
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from f2f09d1 to 205717e Compare June 10, 2026 16:43
Base automatically changed from feat/v0.2-prefetch to main June 10, 2026 18:27
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from 205717e to 89fa2e5 Compare June 10, 2026 18:28
@nh13

nh13 commented Jun 10, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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.

🧹 Nitpick comments (1)
prmi/src/index/spectrum.rs (1)

2112-2127: ⚡ Quick win

Update these doc comments to match the current implementation.

These comments now describe mem_search_backward_from_hint, not mem_search_backward: Lines 1577-1580 still route mem_search_backward through backward_spectrum_inner_into, and the lower search is still launched from [pred - err, pred + err + 1) at Lines 2151-2153 rather than a unit seed at pred.

Also applies to: 2166-2171

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@prmi/src/index/spectrum.rs` around lines 2112 - 2127, Update the doc comment
to accurately describe the current behavior: state that these comments document
mem_search_backward_from_hint (not mem_search_backward), and clarify that
mem_search_backward now routes through backward_spectrum_inner_into; change the
description of the lower-bound search to say it is launched from a unit seed at
`pred` (not from the full model window `[pred - err, pred + err + 1)`), and note
that the model window is only a hint for the gallop but the actual boundary
search uses unit seeds at `pred` (lower) and at the chosen lower probe (upper).
Also update the nearby similar comment block referenced around
`find_boundary`/`mem_search_backward` so both blocks consistently describe the
seeding and probe-count behavior of `mem_search_backward_from_hint`,
`mem_search_backward`, and `find_boundary`.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@prmi/src/index/spectrum.rs`:
- Around line 2112-2127: Update the doc comment to accurately describe the
current behavior: state that these comments document
mem_search_backward_from_hint (not mem_search_backward), and clarify that
mem_search_backward now routes through backward_spectrum_inner_into; change the
description of the lower-bound search to say it is launched from a unit seed at
`pred` (not from the full model window `[pred - err, pred + err + 1)`), and note
that the model window is only a hint for the gallop but the actual boundary
search uses unit seeds at `pred` (lower) and at the chosen lower probe (upper).
Also update the nearby similar comment block referenced around
`find_boundary`/`mem_search_backward` so both blocks consistently describe the
seeding and probe-count behavior of `mem_search_backward_from_hint`,
`mem_search_backward`, and `find_boundary`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0f6db5cc-1ebf-4c75-ada4-ad16d6d333e3

📥 Commits

Reviewing files that changed from the base of the PR and between 942787e and 89fa2e5.

📒 Files selected for processing (1)
  • prmi/src/index/spectrum.rs

Extract the per-base interval search in backward_spectrum_inner_into into
backward_locate_step, and seed its upper bound at the just-found `lower` (gallop
right, ~2*log2(occ) probes) instead of galloping back from the model's loose
right edge `win_hi`; the lower bound keeps the model error window. On the
synthetic occ~2028 repeat the backward full trace drops from 1550 to 1480
probes/call.

Byte-identical: find_boundary is seed-independent — the gallop brackets the true
boundary from any seed, so the seed sets only the probe count, never the
interval returned (existing equality proptests).
@nh13
nh13 force-pushed the feat/v0.2-gallop branch from 89fa2e5 to 7c8ae2a Compare June 10, 2026 20:36
@nh13

nh13 commented Jun 10, 2026

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 10, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

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 df1f820 into main Jun 10, 2026
4 checks passed
@nh13
nh13 deleted the feat/v0.2-gallop branch June 10, 2026 23:34
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