Skip to content

model: residue modification handle as a leaked 'static reference instead of an Arc (#72) - #74

Merged
ypriverol merged 1 commit into
perf/mmap-base-record-cachefrom
perf/mod-handle-no-atomic
Sep 9, 2026
Merged

ypriverol merged 1 commit into
perf/mmap-base-record-cachefrom
perf/mod-handle-no-atomic

Conversation

@ypriverol

Copy link
Copy Markdown
Contributor

Stacked on #73 (base branch perf/mmap-base-record-cache); second lever for #72.

Problem

After #73 the phospho slice still spent 43% in expand_recursive, and a thread-scaling run showed why: for identical output, 16 threads burned 4.7x the CPU of one thread (849 s vs 180 s on a 300-spectrum slice). Every AminoAcid clone during enumeration bumped the atomic refcount of the shared Arc<Modification>; on a phospho search every worker thread hammers the single Phospho record's refcount cache line.

Change

AminoAcid::mod_ is Option<&'static Modification> instead of Option<Arc<Modification>>. The per-search modification table is a few dozen small records built once, so AminoAcidSetBuilder leaks them (leak_mod) and a clone is a pointer copy. with_mod still accepts an owned Modification (via From), so call sites are unchanged apart from dropping the Arc::new. Equality keeps its pointer fast path.

Evidence (cluster, same 300-spectrum phospho slice, same inputs, rows identical: 2,878)

build 1 thr CPU 4 thr CPU 16 thr CPU 16 thr wall
main before #73 – – – 118 s
#73 record cache 180 s 327 s 849 s 66 s
this PR 149 s 202 s 233 s 25 s (14 s search phase)

Profile after: scoring closure 27%, base_records_for_nominal_window 15%, expansion ~24% total, allocator 12%, sorts 8%.

Fixture (E. coli, 4 threads): RAM 11.3 s → 9.6 s, mmap 15.3 s → 14.4 s, PIN byte-identical to the previous build on both backings. cargo test --workspace 1,109 passed; the four ignored RAM/mmap equivalence gates pass.

Full 5,000-spectrum chunk timing on this build is running; will post here.

@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 8, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 5917b299-37bc-4d6e-9284-25fb143767e8

📥 Commits

Reviewing files that changed from the base of the PR and between bfb76fe and be6fdda.

📒 Files selected for processing (13)
  • crates/andes/src/bin/andes/train.rs
  • crates/model-train/tests/neutral_loss_glyco.rs
  • crates/model/src/aa_set.rs
  • crates/model/src/amino_acid.rs
  • crates/model/src/modification.rs
  • crates/output/src/tsv.rs
  • crates/scoring/src/mod_site_features.rs
  • crates/scoring/src/scoring/fragment_ions.rs
  • crates/scoring/src/scoring/psm_score.rs
  • crates/scoring/src/scoring/scored_spectrum.rs
  • crates/search/src/glyco_search.rs
  • crates/search/src/match_engine.rs
  • crates/search/tests/mmap_candidate_backing.rs

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

Full 5,000-spectrum chunk of the phospho search (16 threads, --precursor-cal off, cluster), this stack vs main:

build chunk wall peak RSS rows
main (#71) ~7,100 s – –
#73 + #74, default 4M budget 409 s 13.5 GB 94,171
#73 + #74, 16M budget 428 s 23.5 GB 94,171

About 17x on a whole chunk; the larger cache budget buys nothing here, so the default stays. Whole-file projection ≈ 2.3 h at 16 threads instead of ~40 h.

ypriverol added a commit that referenced this pull request Sep 8, 2026
… MaxQuant reference table (#75)

* benchmarks: phospho tier — dataset, mods, MaxQuant reader, reference table

First PTM-enriched benchmark. PXD007653 (Krahmer/Mann mouse liver EasyPhos, Q Exactive,
single-shot TiO2, label-free), one file: 20151014_QEp6_NaKr_SA_totalliver_control2_phospho.raw,
3.72 GB. Verified against the shipped model store's source ledger — it is NOT training data,
unlike the obvious pick PXD014525, which trained hcd_qexactive_tryp_phosphorylation.

make_truth.py gains a maxquant reader over msms.txt: decoys dropped (Reverse), PEP <= 0.01,
one row per (run, scan), filtered to the run actually searched. It keeps MaxQuant's modified
sequence in a seventh column so localisation can be compared later; emit() widens the header
only when a reader supplies it, so the glyco tables keep their six columns byte-for-byte.
The committed table holds 23,563 spectra, 17,072 of them phospho-bearing.

The depositors searched UP000000589, the same mouse proteome the 1:1 shuffled entrapment
database is built from, so the comparison is like-for-like apart from isoforms.

Numbers follow once the run lands; nothing is claimed here.

* benchmarks: mods file takes one residue per line; NumMods=4

The Phospho line specified STY as a single residue spec, which the parser rejects (it takes
one residue or `*`), so both arms failed at startup. Split into three lines. NumMods raised
3 -> 4 because 0.2% of the reference peptides carry four variable mods and none carry more
than four that we need; at 3 those would be unreachable by construction.

* benchmarks: commit the MaxQuant phospho reference table (PXD007653, one file)

* benchmarks: first PTM-enriched benchmark — PXD007653 phospho, one file, both arms

Default model 36,817–36,922 PSMs @1% (true FDP 1.22–1.32%), --protocol
phospho 36,780–36,884 (1.10–1.14%), ~26.7k phospho-bearing PSMs; 82.1% of
the MaxQuant reference scans covered with 98.3% bare-peptide agreement.
Binary d606d962 (main + #71 + #73 + #74), provenance and recipe recorded.
Site localisation is not scored and is listed as the open gap.
@ypriverol
ypriverol added this pull request to stack #81 September 9, 2026 19:08
…e, not an Arc (#72)

Candidate enumeration clones an AminoAcid per position per variant, and
each clone of a modified residue bumped the atomic refcount of the shared
Modification record. On a phospho search every worker thread hammered the
one Phospho refcount: 16 threads burned 4.7x the CPU of one thread for
identical output (180 s vs 849 s CPU on a 300-spectrum slice). The
per-search modification table is a few dozen records built once, so it
is leaked instead and the handle is a plain pointer copy.

Construction goes through leak_mod / From<Modification>; with_mod keeps
accepting an owned Modification. Output is byte-identical on both
backings.
@ypriverol
ypriverol force-pushed the perf/mod-handle-no-atomic branch from d606d96 to be6fdda Compare September 9, 2026 19:09
@ypriverol
ypriverol merged commit 7142eb0 into main Sep 9, 2026
5 checks passed
@ypriverol
ypriverol deleted the perf/mod-handle-no-atomic 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