Skip to content

perf(BrukerTimsFile): use boost::unordered_flat_map in FrameAggregator - #9243

Merged
timosachsenberg merged 1 commit into
developfrom
perf/bruker-tims-flat-hash-map
Apr 29, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
perf/bruker-tims-flat-hash-map

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Swap std::unordered_map for boost::unordered_flat_map (Boost 1.81+, already required) in FrameAggregator's three hot maps: grid_, denoised, smoothed.
  • Open-addressing eliminates per-node allocations and pointer chasing, which were dominating profile time in the picker (finalize / finalizeCentroided).
  • Adds reserve() for the per-call denoised/smoothed temporaries to avoid rehash cascades.

Measured impact

Single run of BrukerTimsFile_test directly (with ENABLE_OPENTIMS_TESTS=ON), DIA test data (8 window groups × 24 windows × 2823 MS2 frames, 50 M raw MS2 peaks):

Picker time (chrono-measured, summed across all 8469 calls per load):

Path std::unordered_map boost::unordered_flat_map Speedup
finalize (denoise only) 31.1 s 14.5 s 2.1×
finalizeCentroided (denoised, min_support=1) 75.8 s 25.5 s 3.0×
finalizeCentroided (no-denoise, min_support=0) 222.9 s 69.8 s 3.2×

Section + total wall time:

baseline flat-map Δ
DIA MS2 centroiding section 368 s 45 s −323 s
DIA MS1 agg+centroiding section 239 s 101 s −138 s
DIA MS1 aggregation section 202 s 140 s −62 s
DIA loadDIAStreaming section 105 s 63 s −42 s
Test wall total 2189 s 1802 s −387 s (−17.7 %)

DDA MS1 aggregation also goes through FrameAggregator and benefits, but per-section variance was too high in this single run to quote a clean number.

Why this works

FrameAggregator::grid_ keys on uint64_t with a 16-byte Cell value; the picker walks every cell doing 5×5 neighbor lookups (~40 hash probes per cell during smoothing + local-max + centroid). With std::unordered_map's node-per-entry layout, each probe touches a fresh cache line. Open-addressing keeps keys + values contiguous and SIMD-friendly.

API compatibility

boost::unordered_flat_map is API-compatible with std::unordered_map for the operations this code uses: operator[], find, count, end, range-for over [key, value], reserve, clear, size. No call sites needed changes.

Numerical equivalence

for (const auto& [key, val] : map) walks entries in different order between std::unordered_map and boost::unordered_flat_map. The picker code sums doubles, so individual cell intensities can differ by ≤1 ULP from rehash. This was already the case across libstdc++ vs libc++ vs different Boost versions — the test asserts on counts and ratios, not bit-exact m/z, and continues to pass.

Test plan

  • BrukerTimsFile_test passes locally with ENABLE_OPENTIMS_TESTS=ON
  • CI green on develop

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Optimized internal data structures for improved processing performance.

Swap std::unordered_map for boost::unordered_flat_map (Boost 1.81+ API,
already required) in the three hot maps inside FrameAggregator: grid_,
denoised, smoothed. Open-addressing eliminates per-node allocations and
pointer-chasing, which dominated profile time across the DIA/DDA MS1
and DIA MS2 aggregation+centroiding paths.

Measured on a single ~344 MB DIA-PASEF .d (8 window groups, 24 windows,
2823 MS2 frames) running BrukerTimsFile_test directly:

  Picker (FrameAggregator::finalize / finalizeCentroided), per call:
    finalize                            31.1 s ->  14.5 s  (2.1x)
    finalizeCentroided (denoised)       75.8 s ->  25.5 s  (3.0x)
    finalizeCentroided (no-denoise)    222.9 s ->  69.8 s  (3.2x)

  End-to-end test wall:                 2189 s -> 1802 s   (-17.7%)

Includes denoised.reserve()/smoothed.reserve() in finalizeCentroided
to avoid rehash cascades while filling the per-call temporaries.

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

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 706b2a6b-7533-4912-b0c6-fbd24f26fc5a

📥 Commits

Reviewing files that changed from the base of the PR and between 7b0cfb5 and 56fe115.

📒 Files selected for processing (1)
  • src/openms/source/FORMAT/BrukerTimsFile.cpp

📝 Walkthrough

Walkthrough

The FrameAggregator class in BrukerTimsFile.cpp replaces std::unordered_map containers with boost::unordered_flat_map for internal storage, including the grid_ member and temporary denoised/smoothed maps in finalizeCentroided(). Capacity is pre-reserved to optimize memory allocation.

Changes

Cohort / File(s) Summary
Container Optimization
src/openms/source/FORMAT/BrukerTimsFile.cpp
Replaced std::unordered_map with boost::unordered_flat_map for grid_ member variable and temporary maps (denoised, smoothed) in finalizeCentroided(). Added capacity reservations using .reserve() calls to pre-allocate space based on known sizes.

Suggested reviewers

  • jcharkow

Poem

Flat maps are sleeker, much more lean,
A hop through memory so pristine,
Pre-reserved and tightly wound,
Where efficiency is found! 🐰✨

🚥 Pre-merge checks | ✅ 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 and concisely describes the main change: using boost::unordered_flat_map in FrameAggregator for performance optimization, matching the core modification in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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/bruker-tims-flat-hash-map

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

Comment @coderabbitai help to get the list of available commands and usage tips.

@timosachsenberg
timosachsenberg merged commit 178ea9a into develop Apr 29, 2026
70 of 71 checks passed
@timosachsenberg
timosachsenberg deleted the perf/bruker-tims-flat-hash-map branch April 29, 2026 21:03
timosachsenberg pushed a commit that referenced this pull request Apr 30, 2026
Added entries for:
- Perf: BrukerTimsFile FrameAggregator boost::unordered_flat_map (#9243)
- Native .featureparquet and .consensusparquet formats (#9242)
- IsobaricWorkflow: .idparquet and .mzId input support (#9241)
- IDMerger: fix preserved input file order (#9240)
- PercolatorAdapter: fix in-process post-filter (#9240)
- IDRipper: .idparquet input/output support (#9237)
- ProteomicsLFQ: .idparquet and .mzId input support (#9236)
- FileTypes::FEATUREPARQUET, FileTypes::CONSENSUSPARQUET in Library section (#9242)

Co-authored-by: GitHub Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
timosachsenberg added a commit that referenced this pull request Apr 30, 2026
Added entries for:
- IDRipper .idparquet input/output support (#9237)
- FEATUREPARQUET and CONSENSUSPARQUET file types (#9242)
- BrukerTimsFile FrameAggregator perf improvement with boost::unordered_flat_map (#9243)
- PercolatorAdapter: fix post-filters on in-process backend (#9240)
- IDMerger: fix input file order preservation (#9240)
- ProteomicsLFQ: .idparquet/.mzId input support (#9236)
- IsobaricWorkflow: .idparquet/.mzId input support (#9241)
- wnetalign/wnet/pylmcf FetchContent dependencies (#8992)
- OpenMS Library: FileTypes::FEATUREPARQUET/CONSENSUSPARQUET (#9242)
- OpenMS Library: FeatureGroupingAlgorithmWNet and WNetMatcher (#8992)

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: timosachsenberg <[email protected]>
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