Skip to content

Remove unneeded expensive copies (perf, parallel hot paths) - #9686

Merged
timosachsenberg merged 1 commit into
developfrom
perf/remove-unneeded-copies
Jun 30, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
perf/remove-unneeded-copies

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Removes avoidable heavy copies across src/openms, found by an audit focused on OpenMP parallel regions and hot loops. All changes are const& conversions or std::moves of dead values — no behavior change.

Each edit was specifically vetted to ensure it is not a deliberate thread-local snapshot for parallelization safety:

  • const& conversions only target objects that are already thread-local (constructed per-iteration) or shared read-only input (never mutated in the region).
  • std::move targets are dead thread-local locals written to distinct per-thread indices.

Intentional copies (e.g. std::set const-iterator copies, sort-sink params, copies that mutate while the source must stay intact) were identified and left untouched.

Changes

Area Change
OPXLHelper digestDatabase takes FASTA DB by const& (was a whole-DB copy); alpha/beta sequences bound as const& inside the OpenMP candidate loop
MultiplexFilteringProfile Reference the per-peak satellites multimap instead of copying it inside the OpenMP loop
MzMLSqliteHandler std::move block-local compressed payload strings into output vectors (8 sites, two OpenMP encoding loops)
SwathFileConsumer Reference getPrecursors() instead of copying the vector per MS2 spectrum
SimpleSearchEngineAlgorithm / ProSEAlgorithm const& the reannotated AASequence; std::move PeptideHit/hit-vector into setHits
NuXLAnnotateAndLocate std::move dead fragment-annotation vectors
NuXLFDR Append to the mutable getHits() reference instead of copying the hit vector out and back
MzXMLHandler std::move spectra into addSpectrum (batch cleared afterwards)
ConsensusMap::appendColumns std::move mutated loop copies into the unassigned-ID and consensus-feature lists
TransferFDRModel Iterate acceptors_ by const& to avoid shared_ptr refcount churn

Testing

  • Full OpenMS library + all targets build clean (0 errors).
  • ctest full suite: all class/unit tests covering the modified classes pass — OPXLHelper_test (relinked against the new signature), ConsensusMap_test, MzMLSqliteHandler_test, MultiplexFilteringProfile_test, OpenPepXLAlgorithm_test, all ProSE_* / OpenNuXL_* / SimpleSearchEngine_1/2 / FalseDiscoveryRate_*.
  • The only suite failures are pre-existing / environmental and unrelated to this branch (missing Comet binary → CometAdapter/DatabaseSuitability; a develop-side -Search:decoys auto CLI drift from [ProSE] Default tolerances + auto decoy mode (prefix/suffix), reconciled with FDR decoupling #9644; a GLPK solver assertion in MRMFeatureSelector_test). None touch files changed here.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor

    • Reduced unnecessary copies by switching multiple internal collections to read-only references and using move semantics when transferring ownership.
    • Streamlined peptide-hit, precursor, candidate, feature, and consensus-map handling during post-processing and merging.
  • Performance

    • Lowered memory churn and improved throughput across identification post-processing and map merging.
    • Improved robustness during export of spectra/chromatograms by safely handling empty data when building encoded payloads.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 20bb2058-6dda-444c-b4d0-63a0d3a367dc

📥 Commits

Reviewing files that changed from the base of the PR and between 301e910 and fa0f865.

📒 Files selected for processing (12)
  • src/openms/include/OpenMS/ANALYSIS/XLMS/OPXLHelper.h
  • src/openms/include/OpenMS/FORMAT/DATAACCESS/SwathFileConsumer.h
  • src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
  • src/openms/source/ANALYSIS/MAPMATCHING/PIPECHO/TransferFDRModel.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLAnnotateAndLocate.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLFDR.cpp
  • src/openms/source/ANALYSIS/XLMS/OPXLHelper.cpp
  • src/openms/source/FEATUREFINDER/MultiplexFilteringProfile.cpp
  • src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp
  • src/openms/source/FORMAT/HANDLERS/MzXMLHandler.cpp
  • src/openms/source/KERNEL/ConsensusMap.cpp
✅ Files skipped from review due to trivial changes (3)
  • src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp
  • src/openms/source/ANALYSIS/MAPMATCHING/PIPECHO/TransferFDRModel.cpp
  • src/openms/include/OpenMS/FORMAT/DATAACCESS/SwathFileConsumer.h
🚧 Files skipped from review as they are similar to previous changes (8)
  • src/openms/source/KERNEL/ConsensusMap.cpp
  • src/openms/include/OpenMS/ANALYSIS/XLMS/OPXLHelper.h
  • src/openms/source/FEATUREFINDER/MultiplexFilteringProfile.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLFDR.cpp
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLAnnotateAndLocate.cpp
  • src/openms/source/FORMAT/HANDLERS/MzXMLHandler.cpp
  • src/openms/source/ANALYSIS/XLMS/OPXLHelper.cpp

📝 Walkthrough

Walkthrough

This PR replaces several pass-by-value copies with const references and uses std::move when transferring objects into containers across analysis, format, feature-finder, and kernel code paths. One public helper signature changes in digestDatabase.

Changes

Const-ref and move semantics optimizations

Layer / File(s) Summary
Const-ref parameters and loop variable changes
src/openms/include/OpenMS/ANALYSIS/XLMS/OPXLHelper.h, src/openms/source/ANALYSIS/XLMS/OPXLHelper.cpp, src/openms/include/OpenMS/FORMAT/DATAACCESS/SwathFileConsumer.h, src/openms/source/FEATUREFINDER/MultiplexFilteringProfile.cpp, src/openms/source/ANALYSIS/MAPMATCHING/PIPECHO/TransferFDRModel.cpp
digestDatabase changes fasta_db to a const reference, consumeSpectrum binds precursors as a const reference, filter() binds satellites as a const reference, and compute_qvalues iterates over acceptors_ by const reference.
Move semantics in ID hit storage
src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp, src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
PeptideHit objects and hit vectors are moved into PeptideIdentification, and the selected modified peptide is bound as a const reference.
Move semantics in NuXL flows
src/openms/source/ANALYSIS/NUXL/NuXLAnnotateAndLocate.cpp, src/openms/source/ANALYSIS/NUXL/NuXLFDR.cpp
fas is moved into fragment_annotations in three branches, and merged peptide hits are appended through a direct reference with const-reference iteration.
Reference bindings in XLMS helpers
src/openms/source/ANALYSIS/XLMS/OPXLHelper.cpp
buildCandidates binds seq_first and seq_second as const references to candidate sequence fields.
Move semantics in format handlers and kernel merges
src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp, src/openms/source/FORMAT/HANDLERS/MzXMLHandler.cpp, src/openms/source/KERNEL/ConsensusMap.cpp
MzMLSqliteHandler moves encoded strings and checks for empty input before building temporary strings, MzXMLHandler moves spectra into exp_, and ConsensusMap::appendColumns moves peptide identifications and consensus features.

Suggested Reviewers

  • jpfeuffer

🐇 I hop through code both lean and light,
With refs and moves, the paths feel right.
No copied hops, just swift new trails,
A tidy PR with nimble tails.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.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 summarizes the PR’s main change: removing unnecessary expensive copies for performance.
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.
✨ 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/remove-unneeded-copies

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.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp`:
- Around line 1111-1113: The raw-buffer compression path in MzMLSqliteHandler is
unsafe for empty vectors because it builds a std::string from
&data_to_encode[0], which is undefined when spectra or chromatogram buffers are
empty. Update the lossless branches in the affected encoding logic (including
the spectrum and chromatogram intensity/mz handling paths) to guard against
empty data before constructing the buffer string, and ensure empty inputs
produce an empty encoded payload without touching the raw pointer.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1930ccd0-93cf-47c6-b592-7fb3db966e40

📥 Commits

Reviewing files that changed from the base of the PR and between 87d3610 and 301e910.

📒 Files selected for processing (12)
  • src/openms/include/OpenMS/ANALYSIS/XLMS/OPXLHelper.h
  • src/openms/include/OpenMS/FORMAT/DATAACCESS/SwathFileConsumer.h
  • src/openms/source/ANALYSIS/ID/ProSEAlgorithm.cpp
  • src/openms/source/ANALYSIS/ID/SimpleSearchEngineAlgorithm.cpp
  • src/openms/source/ANALYSIS/MAPMATCHING/PIPECHO/TransferFDRModel.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLAnnotateAndLocate.cpp
  • src/openms/source/ANALYSIS/NUXL/NuXLFDR.cpp
  • src/openms/source/ANALYSIS/XLMS/OPXLHelper.cpp
  • src/openms/source/FEATUREFINDER/MultiplexFilteringProfile.cpp
  • src/openms/source/FORMAT/HANDLERS/MzMLSqliteHandler.cpp
  • src/openms/source/FORMAT/HANDLERS/MzXMLHandler.cpp
  • src/openms/source/KERNEL/ConsensusMap.cpp

Eliminate avoidable heavy copies found by an audit of src/openms, with
emphasis on OpenMP parallel regions and hot loops. Each change was verified
not to be a deliberate thread-local snapshot: const& conversions only target
already-thread-local objects or shared read-only input, and std::move targets
are dead thread-local locals.

- OPXLHelper: pass FASTA DB to digestDatabase by const& (was whole-DB copy);
  bind alpha/beta sequences as const& inside the OpenMP candidate loop.
- MultiplexFilteringProfile: reference the per-peak satellites multimap
  instead of copying it inside the OpenMP loop.
- MzMLSqliteHandler: std::move the block-local compressed payload strings into
  the per-index output vectors (8 sites, two OpenMP encoding loops). Also guard
  the lossless raw-buffer path against empty spectra/chromatograms (avoid UB
  from &data_to_encode[0] on an empty vector).
- SwathFileConsumer: reference getPrecursors() instead of copying the vector
  per MS2 spectrum.
- SimpleSearchEngineAlgorithm / ProSEAlgorithm: const& the reannotated
  AASequence; std::move PeptideHit/hit vector into setHits.
- NuXLAnnotateAndLocate: std::move dead fragment-annotation vectors.
- NuXLFDR: append to the mutable getHits() reference instead of copying the
  hit vector out and back.
- MzXMLHandler: std::move spectra into addSpectrum (batch cleared afterwards).
- ConsensusMap::appendColumns: std::move mutated loop copies into the
  unassigned-ID and consensus-feature lists.
- TransferFDRModel: iterate acceptors_ by const& to avoid shared_ptr refcount
  churn.

Builds clean; all unit/class tests for the affected classes pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@timosachsenberg
timosachsenberg force-pushed the perf/remove-unneeded-copies branch from 301e910 to fa0f865 Compare June 30, 2026 09:16
@timosachsenberg
timosachsenberg merged commit 9cffb90 into develop Jun 30, 2026
41 checks passed
@timosachsenberg
timosachsenberg deleted the perf/remove-unneeded-copies branch June 30, 2026 11:06
timosachsenberg added a commit that referenced this pull request Jul 1, 2026
… (#9694)

Four recently merged PRs landed on develop without changelog coverage:
the QPXConverter removal was documented but missing its PR reference,
and the QPXFile metavalue-iteration perf fix, the cross-codebase
expensive-copy cleanup, and the EmgFitter1D robustness fix had no
entry at all.


Claude-Session: https://claude.ai/code/session_013oNRGEvcP3d7LMVv2hqAE4

Co-authored-by: Claude <[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