Skip to content

perf: low-res fragment-index path at in-RAM CPU (TMT 171 vs 179 s, UPS1 116.5 vs 119 s), Astral -20% CPU, byte-identical - #127

Merged
ypriverol merged 3 commits into
mainfrom
perf/lowres-index-speed-2
Oct 13, 2026
Merged

ypriverol merged 3 commits into
mainfrom
perf/lowres-index-speed-2

Conversation

@ypriverol

@ypriverol ypriverol commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

This PR makes the fragment-index path match the in-RAM path on CPU for low-resolution data, with every output byte-identical. That is the last speed condition before retiring the in-RAM path. The same changes cut Astral's high-res index CPU by about 20%.

Where the gap was

Profiling TMT on main, 8 threads, instrumented, showed that per-spectrum work was already cheaper on the index path. RAM fully scores about 3,186 candidates per spectrum. The index selects 100, and about 32 of those pass the precursor gate.

Per-spectrum CPU, TMT Index RAM
Retrieval 25.7 s (query 18.9, materialise 6.8) 4.2 s
Candidate loop 0.9 s 44.3 s
Features 68.8 s 77 s
Total ~98 s ~125 s

The whole gap was the per-chunk index build: 62 CPU-s and 10.5 s wall over 67 chunks. The record filter alone took 18 CPU-s, because a helper returned three 64-slot SmallVecs by value for each of 29M fetched records.

Changes (each byte-identical)

  1. Record filter (a9a5324b). It sums per-residue minimum and maximum masses that are tabulated once per search, in the same order as before, so the result is bit-identical. The filter runs inside the parallel record fetch, before the sort. Only forms inside an exact precursor window are materialised, widened by 1e-6 Da; the scorer's precursor gate still decides.
    • TMT 196.5 → 179 CPU-s
    • UPS1 131.5 → 120.5 CPU-s
  2. Index query (daf9aae5). A block offset table per bin, about 16 entries per cell, replaces the per-bin binary search for the precursor window's start. Index memory grows by about 3%.
    • Query CPU 19.2 → 14.2 s
  3. Record fetch (6f73af7b). It touches each batch of 32 records' protein spans before filtering them, so the cache misses overlap.
    • Fetch CPU 10.2 → 5.7 s

Measurements

The cleanest comparison: RAM against this branch, interleaved, 8 threads, warm cache, with no other jobs on the machine.

Dataset Path CPU Wall CPU % RSS
TMT in-RAM 179 s 28.2 s 632% 6.0 GB
TMT index, this PR 171 s 28.3 s 603% 1.7 GB
UPS1 in-RAM 119 s 18.45 s ~645% 2.5 GB
UPS1 index, this PR 116.5 s 18.3 s ~637% 1.3 GB

A second round compared main against this branch, two repeats each. It ran while other jobs shared the machine (load 9–13), so its wall times are noisy:

Run main CPU this PR CPU
TMT index 177–181 s 150–151 s
UPS1 index 116–132 s 105–110 s
Astral default (high-res index) 547–593 s 444–457 s

Output and identifications

  • Every PIN is byte-identical to main's in all 40 runs: TMT RAM cc21d15c58, TMT index 73978cf0b1, UPS1 RAM ab3d9bc861, UPS1 index 3b0f9ae0b4, Astral 339077c5e0.
  • RSS is unchanged.
  • clippy -D warnings is clean, and 1,140 tests pass.

Summary by CodeRabbit

  • Performance

    • Search now narrows candidate records to those whose possible peptide masses overlap the requested range, reducing unnecessary work.
    • Fragment searches scan relevant precursor-mass ranges more efficiently.
  • Search Accuracy

    • Fragment results are selected across the combined precursor range and restricted to the applicable exact mass windows, with a small tolerance to account for rounding.

…ue mass bounds during the fetch, and materialises only forms inside an exact precursor window

The chunk record filter summed per-position variant bounds through a walk that
returned three 64-slot buffers by value; it now sums bounds tabulated once per
search, in the same order, and runs inside the parallel record scan so only
kept records are sorted. Forms outside every exact (charge, isotope) window are
dropped after top-k selection instead of being materialised and rejected by the
scorer's precursor test. Output byte-identical.

TMT 8 threads: 196.5 -> 179 s CPU, 32.5 -> 29.4 s wall. UPS1: 131.5 -> 120.5 s CPU, 20.5 -> 18.7 s wall.
…ch bin from a block offset table instead of binary-searching the bin

Form ids are cut into precursor-mass blocks (about 16 entries per bin and
block); the build records where each block starts in every bin after the bin
sort, and a query scans from its first block's offset. Output byte-identical.

TMT index query CPU 19.2 -> 14.2 s, bin sort 8.4 -> 9.5 s; total 175.5 -> 171 s
CPU. UPS1 unchanged.
…s before filtering them, so the cache misses overlap

Records come out of the mass-ordered index in random protein order, and each
filter test missed twice (the protein, then its span) inside a loop body too
long for the misses of neighbouring records to overlap. Output byte-identical.

TMT index record fetch CPU 10.2 -> 5.7 s (wall 2.0 -> 1.3 s); total 173.5 ->
170.5 s CPU. UPS1 117.5 -> 116.5 s.
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because the subscription is no longer active. Ask your workspace admin to reactivate the subscription to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 88fc5f7d-bdcd-448a-b785-781d58d4ec66

📥 Commits

Reviewing files that changed from the base of the PR and between 6f73af7 and 6f73af7.


You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e34ccd37-3753-4962-90e4-bd8731da4840


📥 Commits

Reviewing files that changed from the base of the PR and between 1a9de07 and 6f73af7.



📒 Files selected for processing (3)
  • crates/search/src/candidate_gen.rs
  • crates/search/src/fragment_index.rs
  • crates/search/src/match_engine.rs


Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The search candidate path now computes form-mass bounds for record filtering and supplies filtered records to fragment-index construction. The fragment index partitions bins into mass blocks, limits query scans to relevant blocks, and gates selected forms by widened exact precursor windows.

Changes

Search candidate filtering and fragment indexing

Layer / File(s) Summary
Form-mass bounds and record filtering
crates/search/src/candidate_gen.rs
Form-walk tables store minimum and maximum variant masses. Span bounds support record filtering, and bounded form walking reuses caller-provided buffers.
Mass-block fragment-index queries
crates/search/src/fragment_index.rs
The index stores per-bin offsets for mass blocks. Queries scan blocks covering the combined precursor interval, apply top_k, then keep forms within at least one widened exact precursor window. Tests cover block offsets and sorting.
Filtered candidate collection and index setup
crates/search/src/candidate_gen.rs, crates/search/src/match_engine.rs
Nominal-window scan slices accept an in-place filtering callback. Fragment-index setup filters fetched records by form-mass bounds before building the index.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant MatchEngine
  participant FormWalkTables
  participant retain_records_with_forms_in
  participant ChunkFragmentIndex
  MatchEngine->>FormWalkTables: Build form-walk tables
  MatchEngine->>retain_records_with_forms_in: Filter records using mass bounds
  retain_records_with_forms_in->>FormWalkTables: Read span mass bounds
  MatchEngine->>ChunkFragmentIndex: Build index from filtered records
Loading


Merge Risk: ⚪ Minimal · up to 6f73a

No actionable merge-blocking issue was established; the change is ready for normal checks.

Pre-merge checks | Passed 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 clearly identifies the primary performance change in the low-resolution fragment-index path and reports the relevant CPU and byte-identity results. It is longer than necessary, but it remain…
Docstring Coverage Passed Docstring coverage is 90.91% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 3 files.
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.



✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR



🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@timosachsenberg timosachsenberg left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed 6f73af7 against the declared base (1a9de07). No additional actionable findings.

Checked record filtering, terminal mass bounds, block offsets, precursor-window filtering and candidate ordering through materialisation and scoring. The two fragment-index integration tests and 17 matching unit tests pass. An independent oracle for the block-range arithmetic also passed 288,420 cases, including empty and repeated block boundaries.

I did not reproduce the dataset-level byte-identity or performance measurements.

@ypriverol ypriverol left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Review (perf base of search stack)

Low-res fragment-index path aiming for in-RAM CPU with byte-identical output — good merge candidate if goldens/CI prove identity.

Findings / asks

Sev Finding
Medium “Byte-identical” must be pinned by golden PIN tests on UPS1/TMT slices, not only wall-time tables
Low Keep hidden flags out of the default CLI surface

LLM Fix Brief

Branch: perf/lowres-index-speed-2.
1. Confirm CI runs the PIN golden / equivalence tests that prove byte-identity for low-res index path vs prior baseline.
2. If any non-determinism (rayon tie-break), add (score, peptide-bytes) tie-break before claiming byte-identical.
Acceptance: relevant andes golden tests green on this branch.

@ypriverol
ypriverol merged commit 110099e into main Oct 13, 2026
5 checks passed
@ypriverol
ypriverol deleted the perf/lowres-index-speed-2 branch October 15, 2026 16:05
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.

2 participants