Skip to content

perf: exact-mass candidate lookup, prediction memo, parallel setup, edge-score skip - #105

Merged
ypriverol merged 4 commits into
mainfrom
perf/speed-batch
Oct 5, 2026
Merged

ypriverol merged 4 commits into
mainfrom
perf/speed-batch

Conversation

@ypriverol

@ypriverol ypriverol commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Four speed changes. Three leave output byte-identical; the first is not byte-identical because it fixes a recall bug, explained below.

Changes

1. Exact-mass candidate lookup (search)

  • Before: the in-RAM path walked every candidate in about four nominal-mass buckets per spectrum, then ran matches_precursor up to 4× per candidate. Only ~16% passed.
  • Now: candidates are kept in an exact-mass order. Each (charge, isotope offset) binary-searches it with the same arithmetic as matches_precursor, and the matches are sorted by index so iteration order is unchanged.
  • Also a recall fix. A candidate's bucket key is round(0.9995 × mass). Near a rounding boundary, an accepted candidate (more often at isotope offsets) can fall outside the window's slack, and it was never looked at.
    • On a 120-spectrum Lumos file against human SwissProt, 20 more PIN rows appear (1,390 → 1,410). All are valid precursor matches, mostly 4–5 kDa Cys/Met-rich peptides.
    • The low-res fixture is byte-identical.
    • A new test checks that the lookup returns every candidate matches_precursor accepts, for ppm and Da tolerances, z 2–4, isotope offsets −1..2.

2. Memoised fragment-intensity predictions (scoring)

  • The 19 fragment features never depend on the spectrum, so rows repeat across candidates and spectra.
  • A per-thread map from row bits to the raw GBDT value. It is keyed to the model by its tree storage and capped at 2^17 rows per thread.
  • Misses are still predicted together as one batch. Byte-identical.

3. Parallel setup (search)

  • Candidate enumeration runs one protein per rayon task; the ordered collect keeps the sequence.
  • Collision-decoy relabelling hashes each bare sequence once and keeps exact copies only of targets whose hash a decoy shares, instead of boxing every target sequence into one set.
  • Labels and order are unchanged. Byte-identical.

4. Skip edge scoring when the model cannot score edges (scoring, search)

  • Every low-res model scores edges at 0, yet psm_edge_score still built per-residue arrays for every candidate, and the gate's bound of 10 per residue never pruned.
  • Now it returns early, and the gate uses a bound of 0, tie-inclusive.
  • Models that do score edges take the unchanged path. Byte-identical.

Measured so far (local x86 build under Rosetta, human SwissProt, 8 threads)

main this PR
low-res MGF (5,760 spectra): scoring phase 16.4 s ~5.8 s on the quietest run
low-res: setup (enumeration + relabel) ~11 s ~4 s
high-res 120-spectrum file: whole process 25.2 s 5.7 s

These timings come from a loaded laptop: the same binary varied 5.7–14 s on the scoring phase between runs. They show direction, not size.

Still to do before merging

  • Benchmark VM: wall time and PSMs at 1% on Astral, TMT and UPS1 against main, in one session.
  • Astral count: check how far change 1 moves it. TMT and UPS1 are expected identical, as for the low-res fixture.

Local cargo test --workspace and clippy (-D warnings) pass.

Summary by CodeRabbit

  • Performance

    • Candidate generation and fragment-intensity prediction now use parallel processing and reuse cached results, which can speed up searches.
    • Precursor candidates are looked up by mass, with tolerance checks retained to include valid matches.
  • Scoring

    • Edge scoring is skipped when required scoring data is unavailable. Candidate ties are retained during queue pruning when edge scoring is disabled.

The in-RAM path walked every candidate in about four nominal-mass
buckets per spectrum and ran matches_precursor on each; only ~16% pass.
Candidates are now kept in an exact-mass order and binary-searched per
(charge, isotope offset) with the same arithmetic as matches_precursor,
then sorted by index so iteration order is unchanged. Candidates that
fail the precursor check had no side effects, so this only skips work.

It also visits candidates the nominal window missed. A candidate's key
is round(0.9995 x mass); near a rounding boundary the observed mass and
an accepted candidate (more often at isotope offsets) fall into
different integers beyond the window's slack. On a 120-spectrum Lumos
file against human SwissProt, 20 more PIN rows appear (1,390 -> 1,410),
all valid precursor matches, mostly 4-5 kDa Cys/Met-rich peptides. The
low-res fixture's PIN is byte-identical.

Local x86 build under Rosetta, human SwissProt, 8 threads: low-res
34.8 -> 29.1 s, high-res 25.2 -> 22.7 s (whole process).
The 19 fragment features describe the ion and peptide, never the
spectrum, so the same rows are predicted again and again across
candidates and spectra. predict_frag_intensities now keeps a per-thread
map from the row's bits to the raw GBDT value, keyed to the model by its
tree storage and capped at 2^17 rows per thread (cleared when full).
Misses still go through predict_value_batch together; a row's value does
not depend on the rest of the batch, so output is bit-identical.

Local x86 build under Rosetta, human SwissProt, 8 threads, both PINs
byte-identical to the previous commit: low-res 29.1 -> 22.0 s,
high-res 22.7 -> 16.0 s.
…llel

Setup was serial: enumeration ~5 s and collision-decoy relabelling ~6 s
on human SwissProt (7.6M candidates), at any thread count, on every
file a pipeline searches.

Enumeration now runs one protein per rayon task; the ordered collect
keeps the (protein, offset, mod combination) order. Relabelling hashes
each bare sequence once, keeps exact copies only of targets whose hash a
decoy shares, and confirms decoys against those, instead of boxing
every target sequence into one set. Labels are exactly as before.

Both fixture PINs are byte-identical. Setup on the local x86 build
under Rosetta: ~8-10 s -> ~4 s.
ScoredSpectrum::edge_score returns 0 for every edge when the model has
no mass-error distribution or ion-existence table, which is every
low-res model. psm_edge_score still built per-residue prefix arrays for
every precursor-matched candidate, and the two-stage gate used a bound of
10 per residue, so it never pruned.

psm_edge_score now returns 0 up front in that case, and the gate uses a
bound of 0 with a tie-inclusive comparison (the queue keeps ties).
Models that do score edges take the unchanged path. Both fixture PINs
are byte-identical.
@coderabbitai

coderabbitai Bot commented Oct 5, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4629e183-dd22-41b5-9a4c-1164e027e2b0
📥 Commits

Reviewing files that changed from the base of the PR and between 7d1e456 and a0e85cd.

📒 Files selected for processing (5)
  • crates/scoring/src/scoring/mod.rs
  • crates/scoring/src/scoring/psm_score.rs
  • crates/scoring/src/scoring/strong_score.rs
  • crates/search/src/candidate_gen.rs
  • crates/search/src/match_engine.rs
 ___________________________________________________________________
< That's not technical debt - that's technical *predatory lending*. >
 -------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@ypriverol

Copy link
Copy Markdown
Contributor Author

Benchmark VM results (8-thread Xeon Gold 6238, Percolator 3.7.1 --seed 42 -Y, binaries alternated, 2 repetitions)

main 7d1e456 vs this PR (a0e85cd), same session:

dataset main wall this PR wall change scoring phase (match_spectra) PSMs @ q≤0.01
Astral 284 / 274 s 205 / 198 s −28% 217 / 214 → 159 / 153 s 38,394 = 38,394
TMT a05058 101 / 93 s 67 / 65 s −32% 52.7 / 51.8 → 37.9 / 36.7 s 12,281 = 12,281
UPS1 55 / 51 s 42 / 41 s −22% 32.5 / 32.1 → 26.0 / 25.6 s 15,838 = 15,838 (166 entrapment hits both)

PIN output:

  • Astral and UPS1: byte-identical to main.
  • TMT: 9 more rows out of 409,262. These are the candidates the old nominal-bucket window skipped (change 1). The accepted count is unchanged.

Comet 2025.01 on the same host the same day took 215 s (Astral), 76 s (TMT) and 46 s (UPS1). With this PR andes is faster than Comet on all three and keeps its PSM lead (+22.1%, +16.9%, +7.5%).

@ypriverol
ypriverol marked this pull request as ready for review October 5, 2026 18:53
@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

@ypriverol
ypriverol merged commit 5e7e6bf into main Oct 5, 2026
4 of 5 checks passed
ypriverol added a commit that referenced this pull request Oct 6, 2026
Re-ran every standard, opt-in, Comet, quick-glyco and phospho benchmark
on the benchmark VM at main 7d1e456, then timed #105 against it.

- Standard, --chimeric, Comet and phospho counts reproduce the previous
  values exactly; #105 leaves the standard counts unchanged.
- With #105, andes is faster than Comet on Astral, TMT and UPS1
  (0.86-0.95x its wall time) with the same 7.5-22.1% PSM lead.
- --refine on Astral is +4.9% (was +14.4% before the decoy and isotope
  fixes); its modified PSMs run at ~3.3% entrapment FDP under the
  merged 1% threshold.
- Quick glyco tier with the bundled mouse glycan list: 7,162
  glycoPSMs, 90.1% / 90.7% confirmed by pGlyco2 / MSFragger.
- UPS1: Comet shows the same entrapment rate as andes.

Historical sections are kept and marked; the deep glyco tier, the
matched-depth comparison and Java MS-GF+ were not re-run.
ypriverol added a commit that referenced this pull request Oct 6, 2026
* docs: refresh benchmarks against current main (2026-10-05)

Re-ran every standard, opt-in, Comet, quick-glyco and phospho benchmark
on the benchmark VM at main 7d1e456, then timed #105 against it.

- Standard, --chimeric, Comet and phospho counts reproduce the previous
  values exactly; #105 leaves the standard counts unchanged.
- With #105, andes is faster than Comet on Astral, TMT and UPS1
  (0.86-0.95x its wall time) with the same 7.5-22.1% PSM lead.
- --refine on Astral is +4.9% (was +14.4% before the decoy and isotope
  fixes); its modified PSMs run at ~3.3% entrapment FDP under the
  merged 1% threshold.
- Quick glyco tier with the bundled mouse glycan list: 7,162
  glycoPSMs, 90.1% / 90.7% confirmed by pGlyco2 / MSFragger.
- UPS1: Comet shows the same entrapment rate as andes.

Historical sections are kept and marked; the deep glyco tier, the
matched-depth comparison and Java MS-GF+ were not re-run.

* docs: add time, CPU and memory against Comet; --refine after #106

- New table (README and docs/benchmarks): wall, CPU time and peak memory
  for andes and Comet on Astral, TMT, UPS1 and phospho, measured with
  /usr/bin/time on the benchmark VM. andes uses 22-43% less CPU time;
  it needs 2x Comet's memory on TMT and phospho.
- --refine row updated for #106: 40,028 PSMs (+4.3%), Pass-2 entrapment
  FDP 2.8% (was 3.3%).
ypriverol added a commit that referenced this pull request Oct 6, 2026
…den --deep-features-top (#111)

* search: in strong mode, compute full features only for the rows that survive the trim

Strong mode retains 25 candidates per spectrum, ranks them by the strong
score and trims to the user's top-N (10). Every retained row got the full
feature set, including the uncached rich-ion GBDT, the fragment-LLR
battery and the site features, although the strong score needs only
features computed before them. Retained rows now get a light pass, and
after the trim the survivors get the full one. The calibrated strong
score is still taken over the whole retained pool.

The survivor pass uses a new TopNQueue::update_in_place that pushes the
heap's elements back in array order, so the layout, and with it the
output order of rows tied on every sort key, is unchanged
(BinaryHeap::from does not preserve it). The main path also reuses the
edge score from the candidate loop instead of recomputing it.

The path-parity guard now also scans the shared make_features closure;
edge_score is set by compute_psm_features_with_edge, so its exception
was stale and is removed. Both fixture PINs are byte-identical to main.

* scoring: evaluate GBDT trees on packed 16-byte nodes

After #105, tree-ensemble evaluation is still 31-45% of CPU on Astral,
TMT and UPS1 (perf on the benchmark VM). Each node visit read five
separate arrays (feature, threshold, left, right, default_left, value).

GbdtPeakModel now builds, on first use, a packed copy of its trees: one
16-byte record per node holding the feature, the threshold (or the leaf
value), the left child and the right child with the NaN direction in its
high bit. predict_value and predict_value_batch walk it with the same
comparisons in the same order, so results are bit-identical; a new test
checks that against Tree::eval, including NaN and short rows. The cache
lives in a new GbdtPeakModel::packed field (construct with
Default::default()); equality ignores it.

Both fixture PINs are byte-identical to main.

* search: hidden --deep-features-top K to compute model features for the best K rows only

Each spectrum emits up to 10 PIN rows, and every row gets the
model-based features (rich-ion LLR GBDT, fragment-LLR battery, site
features). Ranks 2-10 cost about a third of low-res search time. With
--deep-features-top K, all rows take the light pass and only the best K
(by the queue's rank score, ties included) get the full one; the others
keep those columns at 0.0. Default 0 keeps every row, and output is
byte-identical to before. For measurement before any default changes.
@ypriverol
ypriverol deleted the perf/speed-batch 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.

1 participant