Skip to content

perf(FragmentIndex): shrink bucket size to 4096 for tighter candidate lists - #9203

Merged
timosachsenberg merged 1 commit into
developfrom
perf/fragment-index-bucketsize
Apr 22, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
perf/fragment-index-bucketsize

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace bucketsize_ = sqrt(fi_fragments_.size()) with a fixed bucketsize_ = 4096 in FragmentIndex::build().
  • The sqrt(N) heuristic produces very coarse buckets on large non-specific (immunopeptidomics) indices — e.g. bucket_size 22232 for a 490M-fragment human SNES index — so each query peak scans thousands of fragments far outside its tolerance window.
  • 4096 approximates MSFragger's fixed ~0.02 Da fragment-bin density in the dense 500–1500 Da region, so a bucket now covers roughly one fragment-tolerance window instead of a much wider span.

Benchmark

DN17_Liver_classI_techRep2.mzML, SNES enabled, unspecific cleavage, human SwissProt, 7 ppm precursor / 20 ppm fragment, 8 threads, 45,089,468 SNES mothers:

metric before (sqrt(N)=22232) after (4096) Δ
wall ~91 min 80.6 min −11%
CPU ~603 min 523 min −13%
peak RSS 9.29 GB 9.28 GB ≈0
matched spectra 28,235 28,235 identical

Matched-spectra count is bit-identical to the prior run — bucketing only affects how candidates are traversed, not which ones match.

Notes

  • bucket_min_mz_ memory shrinks slightly (N/4096 floats ≈ 1 MB at N=1B, vs. sqrt(N) ≈ 4 MB).
  • For small indices (fi_fragments_.size() < 4096) the build loop produces a single bucket spanning the whole index; correctness is preserved (the bucket-walk loop degrades to a plain linear scan).
  • The pre-existing OpenMP loop now has finer granularity (~N/4096 iterations vs. sqrt(N)); build-time wall is unchanged on the liver bench.
  • Longer-term: replacing the sorted bucket_min_mz_ vector with a fixed-width m/z bin-offset table would remove the remaining lower_bound gate and tighten candidate lists further — out of scope for this PR.

Test plan

  • CI green on existing FragmentIndex_test and ProSE tests
  • Run a closed-search (tryptic) ProSE invocation and confirm PSM count unchanged
  • Run a SNES immunopeptidomics invocation and confirm PSM count unchanged (done locally — see benchmark above)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Adjusted fragment indexing bucket granularity to improve performance and stability of fragment index lookups during analysis.

… lists

The previous sqrt(N) heuristic produces very coarse buckets on large
immunopeptidomics indices (e.g. bucket_size 22k for a 490M-fragment
non-specific human index). Each query peak then scans thousands of
fragments far outside its tolerance window.

Hard-coding bucket_size to 4096 approximates MSFragger's fixed ~0.02 Da
fragment-bin density in the dense 500-1500 Da region, so a bucket now
covers roughly one fragment-tolerance window instead of a wide sqrt(N)
span.

Benchmark on DN17_Liver_classI_techRep2 (SNES, 45M mothers,
unspecific cleavage, 7 ppm / 20 ppm, 8 threads):

- wall:  91 min -> 80.6 min  (-11%)
- CPU:  603 min -> 523 min   (-13%)
- PSMs: 28235 -> 28235       (identical)
- peak RSS unchanged

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Apr 22, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The fragment bucket size calculation in FragmentIndex::build() has been changed from a dynamic formula based on fragment count to a fixed constant value of 4096. This alters the granularity of fragment partitioning during index construction while preserving all other indexing logic and control flow.

Changes

Cohort / File(s) Summary
Fragment Index Bucket Sizing
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp
Changed bucket size calculation from dynamic sqrt(fi_fragments_.size()) to fixed constant 4096 in FragmentIndex::build(), affecting fragment partitioning granularity during index construction.

Possibly related PRs

Poem

🐰 Buckets bucketing, neat and squared,
Four thousand constant, carefully paired,
Root formulas vanish without a trace,
Fixed precision claims its place! 📊

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: switching FragmentIndex bucket sizing from a sqrt(N) heuristic to a fixed 4096 constant for performance optimization.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/fragment-index-bucketsize

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.

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/ID/FragmentIndex.cpp (1)

1260-1265: Consider extracting the bucket size as a named constant.

The value 4096 is used both here and implicitly assumed by all downstream bucket-walking code paths (query, querySpectrumSNES_, and the test helper fragmentsSorted()). Promoting it to a named constexpr (e.g. static constexpr size_t DEFAULT_BUCKET_SIZE = 4096; in the header, alongside the rationale comment) would make the tuning knob discoverable and grep-able, and let the test file reference the same symbol instead of re-deriving expectations from the raw literal.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/ANALYSIS/ID/FragmentIndex.cpp` around lines 1260 - 1265,
Extract the magic literal 4096 into a named constexpr (e.g. static constexpr
size_t DEFAULT_BUCKET_SIZE = 4096) declared in the class header near the other
member declarations and the rationale comment, then replace the literal use in
FragmentIndex.cpp (assignment to bucketsize_) with that symbol (bucketsize_ =
DEFAULT_BUCKET_SIZE) and update all downstream uses/tests that assume 4096
(functions query, querySpectrumSNES_ and the test helper fragmentsSorted()) to
reference the same constexpr so the tuning value is discoverable and consistent
across production and tests.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/openms/source/ANALYSIS/ID/FragmentIndex.cpp`:
- Around line 1260-1265: Extract the magic literal 4096 into a named constexpr
(e.g. static constexpr size_t DEFAULT_BUCKET_SIZE = 4096) declared in the class
header near the other member declarations and the rationale comment, then
replace the literal use in FragmentIndex.cpp (assignment to bucketsize_) with
that symbol (bucketsize_ = DEFAULT_BUCKET_SIZE) and update all downstream
uses/tests that assume 4096 (functions query, querySpectrumSNES_ and the test
helper fragmentsSorted()) to reference the same constexpr so the tuning value is
discoverable and consistent across production and tests.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 117b7b60-5c90-443f-a5e2-bf90b11a8b48

📥 Commits

Reviewing files that changed from the base of the PR and between c162f2d and c155aa1.

📒 Files selected for processing (1)
  • src/openms/source/ANALYSIS/ID/FragmentIndex.cpp

@timosachsenberg
timosachsenberg merged commit 6cd4128 into develop Apr 22, 2026
45 checks passed
@timosachsenberg
timosachsenberg deleted the perf/fragment-index-bucketsize branch April 22, 2026 07:00
timosachsenberg pushed a commit that referenced this pull request Apr 23, 2026
Restore ProSE/FragmentIndex/File entries dropped by the FeatureFinderCentroided
reorganization commit (#9159) and add new entries for commits merged after the
last sync:

- #9188: ProSE BREAKING: default isotope error range changed to [0,+2]
- #9191: ProSE SNES mother-peptide indexing for non-specific searches
- #9195: ProSE fix: defer PSM FDR when Percolator enabled; valid .pin output
- #9203: FragmentIndex: fixed bucket_size 4096 for tighter candidate lists
- #9204: ProSE: resolve PercolatorAdapter via findSiblingTOPPExecutable
- #9205: ProSE: per-file output isolation + dangling decoy ref crash fix
- #9207: File::rename: cross-device fallback (copy+remove on EXDEV)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
@github-actions github-actions Bot mentioned this pull request Apr 26, 2026
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