Skip to content

perf: expand each out-of-core mass window once per chunk (~1.9x) - #67

Merged
ypriverol merged 1 commit into
mainfrom
perf/mmap-window-cache
Sep 7, 2026
Merged

ypriverol merged 1 commit into
mainfrom
perf/mmap-window-cache

Conversation

@ypriverol

@ypriverol ypriverol commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Rebased onto main now that #66 has merged; this branch is a single commit on top of it.

The out-of-core candidate path was 3–15× slower than in-RAM and the entire gap sat inside the search loop: [PHASE stream_search] 30.9 s out-of-core against 8.0 s in-RAM on the ecoli fixture, index load negligible.

Cause, measured rather than assumed: the in-RAM path enumerates candidates once for the whole run and each spectrum reads a bucket range, while the out-of-core path re-did the base-record fetch, modification expansion, multiplicity replication, decoy relabel and sort for every (spectrum, charge) unit. On that fixture 49,066 search units cover only 1,657 distinct nominal windows — 29.6× mean reuse, every unit sharing its window with another — so about 97% of the work was repeated.

Each chunk now expands its distinct windows once, in parallel, and the scoring loop reads the prepared slice. The hot path takes no lock, memory is bounded to one chunk's distinct windows, and there is a cap beyond which expansion falls back to the direct path.

stream_search, 3 runs mean
no cache: 30.58 / 30.12 / 32.03 s 30.9 s
cached: 13.82 / 16.63 / 18.31 s 16.3 s
in-RAM reference 8.0 s

About 1.9×, ranges disjoint. I would quote it as "about" — the cached runs vary more than I would like.

Byte-identical output: the out-of-core PIN matches the in-RAM PIN in all three modification configurations (default 77,097 rows, fixed-only 75,739, one variable mod 77,129). Full suite 1,084 passed, clippy clean at -D warnings, rustfmt clean.

One assumption checked rather than trusted: the calibration shift is params.precursor_mass_shift_ppm, a run-level constant, so it cannot vary between units of a chunk and correctly does not belong in the cache key.

I also dropped an earlier branch of mine that memoised the multiplicity lookup: it was byte-identical but measured flat (30.0 s vs 30.2 s), because the redundancy was in repeating the whole expansion, not in the lookup inside it.

Summary by CodeRabbit

  • Bug Fixes

    • Improved consistency between memory-mapped and in-memory candidate-index searches.
    • Corrected candidate ordering and duplication handling so both search modes return matching candidates and PIN results.
    • Fixed candidate mass handling for searches involving fixed modifications and variable modifications.
    • Improved handling of collision decoys to ensure consistent search results across candidate-index modes.
  • Tests

    • Added regression coverage comparing results from memory-mapped and in-memory searches across multiple modification configurations.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 683a681d-95c6-4e90-a507-ef6c06a48432

📥 Commits

Reviewing files that changed from the base of the PR and between 1254cb7 and c46c116cec35ddfc3e10e89a4275df8fe01da113.

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

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


📝 Walkthrough

Walkthrough

The Mmap candidate path now matches RAM candidate multiplicity and ordering. It caches expanded nominal-mass windows per chunk. New ignored integration tests compare PIN output for default, fixed, and variable modifications.

Changes

Candidate equivalence

Layer / File(s) Summary
Candidate ordering and multiplicity
crates/search/src/candidate_gen.rs, crates/search/src/match_engine.rs
Candidate sorting now includes record length. Base-record mass recovery subtracts only variable modification deltas.
Mmap expansion and window cache
crates/search/src/match_engine.rs
Mmap expansion deduplicates and replicates candidates, applies RAM-compatible ordering and decoy relabeling, and caches expanded windows per chunk.
Backing equivalence regression tests
crates/andes/tests/mmap_ram_pin_equivalence.rs
Ignored integration tests compare Mmap and RAM PIN headers, row counts, and sorted rows for three modification configurations.

Estimated code review effort: 4 (Complex) | ~45 minutes

Merge Risk: ⚪ Minimal · up to 64643

Out-of-core candidate expansion is reused per nominal mass window within each chunk, reducing search time while retaining the existing direct-expansion fallback and equivalent candidate output behavior.

Sequence Diagram(s)

sequenceDiagram
  participant run_chunk_inner
  participant MmapWindowCache
  participant expand_mmap_window_candidates
  participant PIN_output
  run_chunk_inner->>MmapWindowCache: lookup nominal-mass window
  MmapWindowCache-->>run_chunk_inner: return cached candidates
  run_chunk_inner->>expand_mmap_window_candidates: expand cache miss
  expand_mmap_window_candidates-->>run_chunk_inner: return ordered candidates
  run_chunk_inner->>PIN_output: write search results
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 78.57% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 14 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: expanding each out-of-core mass window once per chunk. It also states the reported performance improvement.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/mmap-window-cache

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.

…r spectrum

The out-of-core candidate path was 3-15x slower than in-RAM, and the whole gap sat
inside the search loop: on the ecoli fixture `[PHASE stream_search]` was 30.9s
out-of-core against 8.0s in-RAM, with index load negligible.

The in-RAM path enumerates candidates ONCE for the run and each spectrum reads a
bucket range. The out-of-core path re-did the base-record fetch, mod expansion,
multiplicity replication, decoy relabel and sort for EVERY (spectrum, charge) unit.
Measured on that fixture: 49,066 search units cover only 1,657 distinct nominal
windows, a 29.6x mean reuse, and every unit shares its window with another. So ~97%
of that work was repeated.

Each chunk now collects the distinct windows of its units, expands each exactly once
(in parallel), and the scoring loop reads the prepared slice. The hot path takes no
lock and memory is bounded to one chunk's distinct windows, with a cap beyond which
expansion falls back to the direct path.

The window key is the nominal bounds only: the calibration shift is
`params.precursor_mass_shift_ppm`, a run-level constant, so it cannot vary between
units of a chunk and does not belong in the key.

  stream_search, 3 runs each, same host/command:
    no cache  30.58 / 30.12 / 32.03 s   mean 30.9
    cached    13.82 / 16.63 / 18.31 s   mean 16.3   -> ~1.9x, ranges disjoint
    in-RAM reference                    8.0

Pure caching: the out-of-core PIN stays byte-identical to the in-RAM PIN in all three
modification configurations (default 77,097 rows; fixed-only 75,739; one variable mod
77,129), which is the equivalence PR #66 established.
@ypriverol
ypriverol force-pushed the perf/mmap-window-cache branch from c46c116 to 646436d Compare September 7, 2026 13:23
@ypriverol
ypriverol merged commit 2f58e95 into main Sep 7, 2026
5 checks passed
@ypriverol
ypriverol deleted the perf/mmap-window-cache branch September 7, 2026 13:25
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