Skip to content

Reduced memory usage in FeatureFinderCentroided - #9159

Merged
cbielow merged 17 commits into
OpenMS:developfrom
TilBln:featurefindercentr
Apr 22, 2026
Merged

cbielow merged 17 commits into
OpenMS:developfrom
TilBln:featurefindercentr

Conversation

@TilBln

@TilBln TilBln commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

FeatureFinderCentroided uses FeatureFinderAlgorithmPicked to find two-dimensional features in given LC-MS data.
The underlying algorithm currently copies the whole MSExperiment into map_ which, as commented in the code already, creates massive memory overhead. By using a rvalue-reference and adjusting the following process to still work as intended, I was able to achieve the following RAM reduction on my M2 MacBook Pro with MacOS Tahoe 26.4 (25E246):

Testfile, reduced to only level 1 with FileFilter TOPP tool as thats the only relevant data for the algorithm:
https://abibuilder.cs.uni-tuebingen.de/archive/openms/Tutorials/Data/MzMLTestFiles/ThermoQExactiveDDA-LFQ2.mzML

----- FileInfo of the testfile: -----

File type: mzML

Instrument: Q Exactive
Mass Analyzer: Fourier transform ion cyclotron resonance mass spectrometer (resolution: 0)

MS levels: 1
Total number of peaks: 11901438
Number of spectra: 7787

Combined Ranges (spectra + chromatograms):
retention time: 0.04 .. 7200.05 sec (120.0 min)
mass-to-charge: 0.00 .. 1649.82
ion mobility: ..
intensity: 2439.15 .. 1961080960.00

Spectrum Ranges:
retention time: 0.04 .. 7199.76 sec (120.0 min)
mass-to-charge: 299.99 .. 1649.82
ion mobility: ..
intensity: 2439.15 .. 1961080960.00

MS Level 1 Ranges:
retention time: 0.04 .. 7199.76 sec (120.0 min)
mass-to-charge: 299.99 .. 1649.82
ion mobility: ..
intensity: 2439.15 .. 1961080960.00

Chromatogram Ranges:
retention time: 0.04 .. 7200.05 sec (120.0 min)
mass-to-charge: 0.00 .. 0.00
intensity: 2588.39 .. 1961080960.00

Number of spectra per MS level:
level 1: 7787

Peak type from metadata (or estimated from data)
level 1: Centroid (Centroid)

Activation methods

Precursor charge distribution:

Number of chromatograms: 1
Number of chromatographic peaks: 57301

Number of chromatograms per type:
total ion current chromatogram: 1

FileInfo took 0.69 s (wall), 0.66 s (CPU), 0.09 s (system), 0.57 s (user); Peak Memory Usage: 277 MB.

----- FeatureFinderCentroided test visual -----

RAM usage chart: (blue before, orange after changes)

mem_reduct_chart

----- Summary -----

The memory usage is around 20% down compared to the version without the rvalue-reference.
All class and helper tests were completed successfully and the results show no differences.
While editing the algorithm, I also made the setdata function private and changed the constness of SpectrumType.
Also, there was a rather non-informing error message present in the program, which I changed to a more informative version.
Finally, I noticed that the Changelog file had to groups of TOPPTool changes, so I reunited them.

Checklist

  • Make sure that you are listed in the AUTHORS file
  • Add relevant changes and new features to the CHANGELOG file
  • I have commented my code, particularly in hard-to-understand areas
  • New and existing unit tests pass locally with my changes
  • Updated or added python bindings for changed or new classes (Tick if no updates were necessary.)

How can I get additional information on failed tests during CI

Click to expand If your PR is failing you can check out

Advanced commands (admins / reviewer only)

Click to expand
  • /reformat (experimental) applies the clang-format style changes as additional commit. Note: your branch must have a different name (e.g., yourrepo:feature/XYZ) than the receiving branch (e.g., OpenMS:develop). Otherwise, reformat fails to push.
  • setting the label "NoJenkins" will skip tests for this PR on jenkins (saves resources e.g., on edits that do not affect tests)
  • commenting with rebuild jenkins will retrigger Jenkins-based CI builds

⚠️ Note: Once you opened a PR try to minimize the number of pushes to it as every push will trigger CI (automated builds and test) and is rather heavy on our infrastructure (e.g., if several pushes per day are performed).

Summary by CodeRabbit

  • Performance

    • FeatureFinderCentroided RAM usage reduced by ~20%.
    • Reduced memory usage in the picked feature finder.
  • Improvements

    • Command-line parameter handling: last occurrence wins; duplicate parameters now warn.
    • Aggregated warnings for out-of-range indexing and improved error messages.
  • Documentation

    • CHANGELOG reorganized to consolidate TOPP tools and related notes.
  • Chore

    • AUTHORS updated to add Tilman Aurich (and an additional Till Englert entry).

@github-actions

Copy link
Copy Markdown
Contributor

Welcome @TilBln and thank you for your contribution to OpenMS! To help us better understand our userbase and contributors, we would appreciate if you could complete the survey at the link below. Completing this survey will help us get to your PR sooner. Thank you for your participation!

Survey

@github-actions

Copy link
Copy Markdown
Contributor

@TilBln The following names might be missing from the AUTHORS file:

  • Tilman Aurich

Please consider applying the following patch:

--- AUTHORS	2026-04-16 09:31:09.667876837 +0000
+++ AUTHORS.new	2026-04-16 09:31:13.475990229 +0000
@@ -5,17 +5,18 @@
 The following authors contributed to OpenMS at some point. For the
 authors contributing to a specific piece of code, please refer to
 the authors tag in the respective file header.
+ - Michael R. Crusoe
  - Achal Bajpai
  - Aditya Muzumdar
  - Ahmed Khalil
  - Alexandra Scherbart
- - Axel Walter
  - Alexandra Zerck
  - Amanda Wein
  - Andreas Bertsch
  - Andreas Simon
  - Anton Kriese
  - Anton Pervukhin
+ - Axel Walter
  - Bastian Blank
  - Chenghao Zhu
  - Chirag Dave
@@ -26,8 +27,8 @@
  - Cornelia Friedle
  - Daniel Jameson
  - Darren Kessner
- - David Wojnar
  - David Voigt
+ - David Wojnar
  - Dhanmoni Nath
  - Dilek Dere
  - Dimitri Schachmann
@@ -54,14 +55,14 @@
  - Jang Jang Jin
  - Jeremi Maciejewski
  - Jihyung Kim
- - Johan Teleman
  - Johannes Junker
  - Johannes Veit
  - Johannes von Kleist
+ - Johan Teleman
  - Joshua Charkow
- - Julia Thueringer
  - Juliane Schmachtenberg
  - Julianus Pfeuffer
+ - Julia Thueringer
  - Justin Sing
  - Katharina Albers
  - Khue Nguyen
@@ -84,7 +85,6 @@
  - Matteo Pilz
  - Matthew The
  - Matthias Bernt
- - Michael R. Crusoe
  - Michał Startek
  - Mohamed Ali
  - Nico Pfeifer
@@ -110,12 +110,12 @@
  - Sven Nahnsen
  - Svetlana Kutuzova
  - Swenja Wagner
- - Taraneh Strunk
  - Tapasweni Pathak
- - Timo Sachsenberg
- - Tinatin Kasradze
+ - Taraneh Strunk
  - Till Englert
  - Tilman Aurich
+ - Timo Sachsenberg
+ - Tinatin Kasradze
  - Tom David Müller
  - Tom Lukas Lankenau
  - Tom Waschischeck

@coderabbitai

coderabbitai Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Updated repository metadata (AUTHORS, CHANGELOG) and refactored FeatureFinderAlgorithmPicked to use move semantics: setData now takes MSExperiment&& (moved internally and made private), added an rvalue run overload, renamed internal helper, tightened const-correctness, and moved apex/native-id post-processing into the algorithm with aggregated warnings.

Changes

Cohort / File(s) Summary
Metadata
AUTHORS, CHANGELOG
AUTHORS updated (added Tilman Aurich, duplicated Till Englert). CHANGELOG updated with TOPP tools notes including duplicate-parameter rule, tool-specific notes (CometAdapter, ProSE, FeatureFinderCentroided, OpenSwathWorkflow).
FeatureFinderAlgorithmPicked — Header
src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h
Added <functional>; made setData private and move-taking (setData_(MSExperiment&&, FeatureMap&)); added rvalue run(PeakMap&&, ...) overload; getDefaultParameters is non-virtual; helper renamed to run_(); features_ pointer initialized.
FeatureFinderAlgorithmPicked — Implementation
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp
Replaced copy-based setData with setData_ that move-assigns map_; public run(PeakMap&) now copies and forwards to rvalue overload; added run(PeakMap&&,...); renamed internal run()→run_(); tightened const-correctness; switched pointer usage to (*features_); moved per-feature "spectrum_index"/"spectrum_native_id" writing into run_() and emit a single aggregated OPENMS_LOG_WARN for out-of-range indices; removed std::cerr fallback.
Caller update
src/topp/FeatureFinderCentroided.cpp
Callsite updated to pass faims_group as std::move(faims_group), enabling move semantics into FeatureFinderAlgorithmPicked's rvalue run overload.

Possibly related PRs

  • some doc improvements #7916 — modifies FeatureFinderAlgorithmPicked and touches FeatureFinderCentroided; likely related changes to run semantics and usages.

Suggested reviewers

  • timosachsenberg
  • cbielow
  • jpfeuffer

Poem

🐇
I hopped through spectra, gentle and spry,
Moved maps in my pouch — no copies to vie,
Features aligned, indices kept dry,
Warnings counted once beneath the sky,
A lighter memory trail — nuzzle and sigh.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 10.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 primary objective of the changeset: reducing memory usage in FeatureFinderCentroided through rvalue references and move semantics to eliminate unnecessary copies.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@CHANGELOG`:
- Around line 131-133: The trailing-arguments note about global command-line
parsing (`#8670`) is incorrectly nested under the "MetaProSIP" section; move that
sentence out of the MetaProSIP bullet list and place it under the global "all:"
subsection (or alternatively convert it into a proper MetaProSIP-specific bullet
if it truly only applies to MetaProSIP). Locate the "MetaProSIP:" heading and
the line "Flags with trailing arguments now produce clearer warnings instead of
cryptic 'trailing text arguments' errors." and either move that sentence up into
the "all:" section as a separate bullet or reformat it as a MetaProSIP-specific
bullet so the changelog accurately reflects scope.

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 1080-1082: The public API currently invalidates callers because
FeatureFinderAlgorithmPicked::run(PeakMap& input_map, ...) takes an lvalue
reference but internally does setData(std::move(input_map), ...); fix by adding
an rvalue overload FeatureFinderAlgorithmPicked::run(PeakMap&& input_map, ...)
that performs the move into setData(std::move(input_map), ...), and change the
existing lvalue overload FeatureFinderAlgorithmPicked::run(PeakMap& input_map,
...) to preserve the caller’s data (e.g., call setData(input_map, ...) or
explicitly copy before calling setData) and remove the std::move usage there;
update any calls and the method documentation to document the ownership
semantics (move-only behavior in the && overload, copy-preserving behavior in
the & overload).
🪄 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: b5b414f8-24f3-44bb-9593-427a185a0926

📥 Commits

Reviewing files that changed from the base of the PR and between 95b6f29 and 674e119.

📒 Files selected for processing (4)
  • AUTHORS
  • CHANGELOG
  • src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h
  • src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp

Comment thread CHANGELOG
Comment on lines +131 to +133
MetaProSIP:
- Added detailed documentation of CSV output column formats (#4400)
Flags with trailing arguments now produce clearer warnings instead of cryptic "trailing text arguments" errors.

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.

⚠️ Potential issue | 🟡 Minor

Move the trailing-arguments note out of MetaProSIP.

Line 133 describes the global command-line parsing change from #8670, but it's currently nested under MetaProSIP, so the changelog reads as if that warning improvement were tool-specific. Please fold it back into the all: subsection or make it a proper MetaProSIP bullet.

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

In `@CHANGELOG` around lines 131 - 133, The trailing-arguments note about global
command-line parsing (`#8670`) is incorrectly nested under the "MetaProSIP"
section; move that sentence out of the MetaProSIP bullet list and place it under
the global "all:" subsection (or alternatively convert it into a proper
MetaProSIP-specific bullet if it truly only applies to MetaProSIP). Locate the
"MetaProSIP:" heading and the line "Flags with trailing arguments now produce
clearer warnings instead of cryptic 'trailing text arguments' errors." and
either move that sentence up into the "all:" section as a separate bullet or
reformat it as a MetaProSIP-specific bullet so the changelog accurately reflects
scope.

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

nice! Thanks

@@ -110,7 +111,10 @@ namespace OpenMS

void setSeeds(const FeatureMap& seeds);

void setData(const MSExperiment& map, FeatureMap& features);
private:
void setData(MSExperiment&& map, FeatureMap& features);

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.

coding convention :)

Suggested change
void setData(MSExperiment&& map, FeatureMap& features);
void setData_(MSExperiment&& map, FeatureMap& features);

setSeeds(seeds);
run();

//report RT apex spectrum index and native ID for each feature
// report RT apex spectrum index and native ID for each feature
// NOTE: use map_ (internal map) here, since input_map was moved in setData().

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.

suggestion: move that code into run(), so input_map is not even accessible (avoids potential for errors)

@@ -1078,28 +1078,36 @@ namespace OpenMS

// do the work
setParameters(param);
setData(input_map, features);
setData(std::move(input_map), features);
setSeeds(seeds);
run();

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.

optional fix (since not part of the PR):
run() is private and should thus be named run_().

@cbielow

cbielow commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Please do a git pull upstream develop and resolve conflicts in AUTHORS and CHANGELOG.
(ask @LuBox2K for details :))

@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

♻️ Duplicate comments (2)
src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h (1)

128-139: ⚠️ Potential issue | 🟠 Major

Public run(PeakMap&, …) signature hides move semantics from callers.

run() still takes PeakMap& (lvalue), but the implementation in .cpp calls setData_(std::move(input_map), …), silently invalidating the caller's map. The @note in the doc is helpful but the signature does not communicate ownership transfer, which is a real footgun (the value is very different: pass-by-ref usually means "readable after call").

Consider splitting into overloads so the contract is expressed in the type system:

Proposed overload split
-    void run(PeakMap& input_map,
+    /// Move overload: consumes `@p` input_map.
+    void run(PeakMap&& input_map,
+      FeatureMap& features,
+      const Param& param,
+      const FeatureMap& seeds);
+
+    /// Copy overload: leaves `@p` input_map unchanged (at the cost of a copy).
+    void run(const PeakMap& input_map,
       FeatureMap& features,
       const Param& param,
       const FeatureMap& seeds);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h`
around lines 128 - 139, The public run(PeakMap& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) hides that the implementation
actually moves from input_map via setData_(std::move(input_map), ...), so
callers may be left with a moved-from map; fix by expressing ownership in the
signature: add an rvalue overload run(PeakMap&& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) that documents/permits move and is
used where setData_ moves, and keep or implement a separate lvalue overload
run(const PeakMap& input_map, FeatureMap& features, const Param& param, const
FeatureMap& seeds) (or a non-moving run(PeakMap&)) that does not move from the
caller (i.e. copies or internally clones) so callers aren’t surprised; update
callers to call the && overload when they intend transfer and adjust
docs/comments around setData_ accordingly.
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp (1)

1059-1108: ⚠️ Potential issue | 🟠 Major

run(PeakMap& input_map, …) moves from an lvalue-reference parameter.

At line 1105 setData_(std::move(input_map), features) invalidates the caller's input_map, but the public signature on line 1059 still advertises an lvalue reference. Callers reading the header will reasonably expect their map to remain usable after run(...) returns. This is the root cause; the @note in the header is a mitigation, not a fix. Prefer making the rvalue contract explicit via overloads (see comment on header), or at minimum document that the parameter is consumed and rename it (e.g., consumed_input_map) to discourage post-call use.

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

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 1059 - 1108, run(PeakMap& input_map, ...) currently std::move's the
parameter via setData_(std::move(input_map), features), which invalidates the
caller's map despite the lvalue-reference signature; change the API to make the
move-semantic explicit by either adding an rvalue overload
FeatureFinderAlgorithmPicked::run(PeakMap&& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) that calls
setData_(std::move(input_map), features) and keeps the existing lvalue overload
but make it copy or document non-consuming behavior, or rename the parameter
(e.g., consumed_input_map) and update the header comment to clearly state the
map is consumed; locate usages of run and update callers to std::move their
PeakMap when they intend to transfer ownership, and ensure setData_ and any
documentation reflect the new contract.
🧹 Nitpick comments (1)
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp (1)

865-993: Nit: introduce a local reference instead of repeating (*features_).

The block now dereferences features_ ~15 times with (*features_).foo() / (*features_)[i] / even (*features_).operator[](i) at lines 986/988. A single local reference improves readability without any behavior change, and makes these hot loops easier to scan:

Proposed cleanup
-    startProgress(0, (*features_).size() * (*features_).size(), "Resolving overlapping features");
-    if (debug_) log_ << "Resolving intersecting features (" << (*features_).size() << " candidates)\n";
+    FeatureMap& features = *features_;
+    startProgress(0, features.size() * features.size(), "Resolving overlapping features");
+    if (debug_) log_ << "Resolving intersecting features (" << features.size() << " candidates)\n";
     //sort features according to m/z in order to speed up the resolution
-    (*features_).sortByMZ();
+    features.sortByMZ();
     //precalculate BBs and maximum mz span
-    std::vector<DBoundingBox<2> > bbs((*features_).size());
+    std::vector<DBoundingBox<2> > bbs(features.size());

…and similarly below, including replacing (*features_).operator[](i) with features[i].

Also note features_->foo() is idiomatic C++ for pointer access and was likely the style used elsewhere in the project before this PR — (*features_). is unusual to choose deliberately.

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

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 865 - 993, Introduce a local reference to avoid repeated dereferencing of
the pointer features_: add something like "auto &features = *features_;" at the
top of the block and then replace all occurrences of "(*features_)" and
"(*features_).operator[](i)" with "features" and "features[i]" respectively;
update calls that use features_-> style accordingly (e.g. sortByMZ() ->
features.sortByMZ(), size() -> features.size(), swapFeaturesOnly(*features_) ->
swapFeaturesOnly(features)) and leave all logic (intersection_, bbs, removed,
startProgress, sortByIntensity) unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 996-1018: The code writes an out-of-range "spectrum_index" meta
value when map_.RTBegin(...) returns map_.end(); change the block around
map_.RTBegin((*features_)[i].getRT()) so you compute and check validity before
setting any meta: call map_.RTBegin, check that the returned iterator is not
map_.end() and that computed spectrum_index < map_.size(), then set both
"spectrum_index" and "spectrum_native_id" via Feature::setMetaValue; if invalid,
do not write "spectrum_index" and instead increment invalid_apex_index_count and
collect identifying info (e.g. feature.getUniqueId() or RT/MZ) to include in the
aggregated OPENMS_LOG_WARN message so the warning preserves per-feature context.

---

Duplicate comments:
In `@src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h`:
- Around line 128-139: The public run(PeakMap& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) hides that the implementation
actually moves from input_map via setData_(std::move(input_map), ...), so
callers may be left with a moved-from map; fix by expressing ownership in the
signature: add an rvalue overload run(PeakMap&& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) that documents/permits move and is
used where setData_ moves, and keep or implement a separate lvalue overload
run(const PeakMap& input_map, FeatureMap& features, const Param& param, const
FeatureMap& seeds) (or a non-moving run(PeakMap&)) that does not move from the
caller (i.e. copies or internally clones) so callers aren’t surprised; update
callers to call the && overload when they intend transfer and adjust
docs/comments around setData_ accordingly.

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 1059-1108: run(PeakMap& input_map, ...) currently std::move's the
parameter via setData_(std::move(input_map), features), which invalidates the
caller's map despite the lvalue-reference signature; change the API to make the
move-semantic explicit by either adding an rvalue overload
FeatureFinderAlgorithmPicked::run(PeakMap&& input_map, FeatureMap& features,
const Param& param, const FeatureMap& seeds) that calls
setData_(std::move(input_map), features) and keeps the existing lvalue overload
but make it copy or document non-consuming behavior, or rename the parameter
(e.g., consumed_input_map) and update the header comment to clearly state the
map is consumed; locate usages of run and update callers to std::move their
PeakMap when they intend to transfer ownership, and ensure setData_ and any
documentation reflect the new contract.

---

Nitpick comments:
In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 865-993: Introduce a local reference to avoid repeated
dereferencing of the pointer features_: add something like "auto &features =
*features_;" at the top of the block and then replace all occurrences of
"(*features_)" and "(*features_).operator[](i)" with "features" and
"features[i]" respectively; update calls that use features_-> style accordingly
(e.g. sortByMZ() -> features.sortByMZ(), size() -> features.size(),
swapFeaturesOnly(*features_) -> swapFeaturesOnly(features)) and leave all logic
(intersection_, bbs, removed, startProgress, sortByIntensity) unchanged.
🪄 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: 96b969cb-6c4a-4837-9cf8-1b1919907747

📥 Commits

Reviewing files that changed from the base of the PR and between 1b1897c and 9d40419.

📒 Files selected for processing (2)
  • src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h
  • src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp

Comment on lines +996 to +1018
// report RT apex spectrum index and native ID for each feature
Size invalid_apex_index_count = 0;
for (Size i = 0; i < (*features_).size(); ++i)
{
// index
Size spectrum_index = map_.RTBegin((*features_)[i].getRT()) - map_.begin();
(*features_)[i].setMetaValue("spectrum_index", spectrum_index);
// native id
if (spectrum_index < map_.size())
{
String native_id = map_[spectrum_index].getNativeID();
(*features_)[i].setMetaValue("spectrum_native_id", native_id);
}
else
{
++invalid_apex_index_count;
}
}
if (invalid_apex_index_count > 0)
{
OPENMS_LOG_WARN << "Could not assign 'spectrum_native_id' for " << invalid_apex_index_count
<< " feature(s), because the computed apex spectrum index was out of range.\n";
}

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.

⚠️ Potential issue | 🟡 Minor

Still writes an out-of-range spectrum_index meta value.

When RTBegin(...) returns map_.end(), spectrum_index == map_.size() and you take the else branch (correctly skipping spectrum_native_id and incrementing the counter), but you have already written spectrum_index as a meta value at line 1002. Downstream consumers will see a meta value that points past the end of the spectra vector, while the previously-emitted per-feature warning is now aggregated into a single log line, losing the per-feature context.

Suggest guarding the write symmetrically and including feature identity in the aggregated warning (or at minimum not writing spectrum_index when it is out of range):

Proposed tightening
-    for (Size i = 0; i < (*features_).size(); ++i)
-    {
-      // index
-      Size spectrum_index = map_.RTBegin((*features_)[i].getRT()) - map_.begin();
-      (*features_)[i].setMetaValue("spectrum_index", spectrum_index);
-      // native id
-      if (spectrum_index < map_.size())
-      {
-        String native_id = map_[spectrum_index].getNativeID();
-        (*features_)[i].setMetaValue("spectrum_native_id", native_id);
-      }
-      else
-      {
-        ++invalid_apex_index_count;
-      }
-    }
+    for (Size i = 0; i < (*features_).size(); ++i)
+    {
+      const Size spectrum_index = map_.RTBegin((*features_)[i].getRT()) - map_.begin();
+      if (spectrum_index < map_.size())
+      {
+        (*features_)[i].setMetaValue("spectrum_index", spectrum_index);
+        (*features_)[i].setMetaValue("spectrum_native_id", map_[spectrum_index].getNativeID());
+      }
+      else
+      {
+        ++invalid_apex_index_count;
+      }
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 996 - 1018, The code writes an out-of-range "spectrum_index" meta value
when map_.RTBegin(...) returns map_.end(); change the block around
map_.RTBegin((*features_)[i].getRT()) so you compute and check validity before
setting any meta: call map_.RTBegin, check that the returned iterator is not
map_.end() and that computed spectrum_index < map_.size(), then set both
"spectrum_index" and "spectrum_native_id" via Feature::setMetaValue; if invalid,
do not write "spectrum_index" and instead increment invalid_apex_index_count and
collect identifying info (e.g. feature.getUniqueId() or RT/MZ) to include in the
aggregated OPENMS_LOG_WARN message so the warning preserves per-feature context.

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

♻️ Duplicate comments (1)
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp (1)

996-1018: ⚠️ Potential issue | 🟡 Minor

Still writes an out-of-range spectrum_index meta value.

When RTBegin(...) returns map_.end(), spectrum_index == map_.size() and you correctly skip spectrum_native_id and count the case, but the spectrum_index meta value has already been written at line 1002 and points past the end of the spectra vector. Downstream consumers that trust this metadata can misindex into map_. Also, the aggregated warning at line 1016 has lost per-feature context (RT/m/z/UniqueId) that would help diagnose the cause.

Proposed tightening
-    Size invalid_apex_index_count = 0;
-    for (Size i = 0; i < (*features_).size(); ++i)
-    {
-      // index
-      Size spectrum_index = map_.RTBegin((*features_)[i].getRT()) - map_.begin();
-      (*features_)[i].setMetaValue("spectrum_index", spectrum_index);
-      // native id
-      if (spectrum_index < map_.size())
-      {
-        String native_id = map_[spectrum_index].getNativeID();
-        (*features_)[i].setMetaValue("spectrum_native_id", native_id);
-      }
-      else
-      {
-        ++invalid_apex_index_count;
-      }
-    }
+    Size invalid_apex_index_count = 0;
+    for (Size i = 0; i < (*features_).size(); ++i)
+    {
+      const Size spectrum_index = map_.RTBegin((*features_)[i].getRT()) - map_.begin();
+      if (spectrum_index < map_.size())
+      {
+        (*features_)[i].setMetaValue("spectrum_index", spectrum_index);
+        (*features_)[i].setMetaValue("spectrum_native_id", map_[spectrum_index].getNativeID());
+      }
+      else
+      {
+        ++invalid_apex_index_count;
+      }
+    }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 996 - 1018, The code currently writes an out-of-range spectrum_index into
each feature before checking validity; change the loop that uses
map_.RTBegin((*features_)[i].getRT()) so you first capture the iterator (auto it
= map_.RTBegin(...)) and only compute/set spectrum_index and spectrum_native_id
when it != map_.end() (or when computed index < map_.size()); when invalid, do
NOT write the "spectrum_index" meta key (or write a special sentinel like
String("n/a") if you prefer) and instead record per-feature context (RT, MZ via
getRT()/getMZ(), and UniqueId via getUniqueId()) into the invalid
counter/collection; after the loop use OPENMS_LOG_WARN to report the failing
features with those per-feature details so callers can diagnose, updating
references to features_, map_, setMetaValue("spectrum_index"),
setMetaValue("spectrum_native_id"), invalid_apex_index_count and OPENMS_LOG_WARN
accordingly.
🧹 Nitpick comments (2)
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp (2)

1059-1063: Lvalue run overload silently deep-copies the entire PeakMap.

The implementation PeakMap input_map_copy(input_map); run(std::move(input_map_copy), ...); preserves the caller’s data as advertised by the header note, but it also means every existing caller that was relying on the old (copy-based) internal behavior now performs an extra full-experiment copy they can’t see from the call site, which can be significant on large maps (e.g. the ~12M-peak test file in the PR description). Consider adding a short OPENMS_LOG_DEBUG line here, and/or emphasizing in the header note that callers who don’t need the input afterwards should prefer the PeakMap&& overload to actually realize the memory savings that motivated this PR. Non-blocking.

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

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 1059 - 1063, The lvalue overload FeatureFinderAlgorithmPicked::run
currently makes a full deep copy of PeakMap (PeakMap input_map_copy(input_map))
and calls the rvalue overload, which can cause unexpected heavy copies for
callers; add an OPENMS_LOG_DEBUG message inside this lvalue overload that
clearly states a full copy is being made and suggests callers use the PeakMap&&
overload when they no longer need the original to avoid the copy, and also
update the function/header comment for FeatureFinderAlgorithmPicked::run to
explicitly document that the lvalue overload performs a deep copy and recommend
preferring the rvalue overload to realize memory/speed savings.

865-993: Optional: bind a local reference to *features_ to improve readability.

The many (*features_). ... / (*features_)[i] / (*features_).operator[](i) expressions (including the rather awkward explicit .operator[] calls on lines 986 and 988) add noise without any semantic benefit. Binding a single reference at the top of the block would make this section substantially easier to read and would keep the generated code identical.

♻️ Proposed refactor
-    startProgress(0, (*features_).size() * (*features_).size(), "Resolving overlapping features");
-    if (debug_) log_ << "Resolving intersecting features (" << (*features_).size() << " candidates)\n";
-    //sort features according to m/z in order to speed up the resolution
-    (*features_).sortByMZ();
-    //precalculate BBs and maximum mz span
-    std::vector<DBoundingBox<2> > bbs((*features_).size());
+    FeatureMap& features = *features_;
+    startProgress(0, features.size() * features.size(), "Resolving overlapping features");
+    if (debug_) log_ << "Resolving intersecting features (" << features.size() << " candidates)\n";
+    //sort features according to m/z in order to speed up the resolution
+    features.sortByMZ();
+    //precalculate BBs and maximum mz span
+    std::vector<DBoundingBox<2> > bbs(features.size());
     double max_mz_span = 0.0;

-    for (Size i = 0; i < (*features_).size(); ++i)
+    for (Size i = 0; i < features.size(); ++i)
     {
-      bbs[i] = (*features_)[i].getConvexHull().getBoundingBox();
+      bbs[i] = features[i].getConvexHull().getBoundingBox();
       ...
     }
     ...
-    for (Size i = 0; i < (*features_).size(); ++i)
+    for (Size i = 0; i < features.size(); ++i)
     {
-      if ((*features_).operator[](i).getIntensity() != 0.0)
+      if (features[i].getIntensity() != 0.0)
       {
-        tmp.push_back((*features_).operator[](i));
+        tmp.push_back(features[i]);
       }
     }
-    tmp.swapFeaturesOnly(*features_);
-    (*features_).sortByIntensity(true);
+    tmp.swapFeaturesOnly(features);
+    features.sortByIntensity(true);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp` around
lines 865 - 993, The code repeatedly dereferences features_ (e.g.,
(*features_).size(), (*features_)[i], (*features_).operator[](i)), making the
block noisy; fix it by binding a local reference (e.g., FeatureMap& features =
*features_ or auto& features = *features_) at the top of the block used in
FeatureFinderAlgorithmPicked.cpp, then replace all uses of (*features_),
(*features_)[i], and operator[] calls with features, features[i], and
features[i] respectively (update uses in startProgress, sortByMZ, size(), BB
computation loop, intersect loop, tmp population, swapFeaturesOnly, and
sortByIntensity calls).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 996-1018: The code currently writes an out-of-range spectrum_index
into each feature before checking validity; change the loop that uses
map_.RTBegin((*features_)[i].getRT()) so you first capture the iterator (auto it
= map_.RTBegin(...)) and only compute/set spectrum_index and spectrum_native_id
when it != map_.end() (or when computed index < map_.size()); when invalid, do
NOT write the "spectrum_index" meta key (or write a special sentinel like
String("n/a") if you prefer) and instead record per-feature context (RT, MZ via
getRT()/getMZ(), and UniqueId via getUniqueId()) into the invalid
counter/collection; after the loop use OPENMS_LOG_WARN to report the failing
features with those per-feature details so callers can diagnose, updating
references to features_, map_, setMetaValue("spectrum_index"),
setMetaValue("spectrum_native_id"), invalid_apex_index_count and OPENMS_LOG_WARN
accordingly.

---

Nitpick comments:
In `@src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp`:
- Around line 1059-1063: The lvalue overload FeatureFinderAlgorithmPicked::run
currently makes a full deep copy of PeakMap (PeakMap input_map_copy(input_map))
and calls the rvalue overload, which can cause unexpected heavy copies for
callers; add an OPENMS_LOG_DEBUG message inside this lvalue overload that
clearly states a full copy is being made and suggests callers use the PeakMap&&
overload when they no longer need the original to avoid the copy, and also
update the function/header comment for FeatureFinderAlgorithmPicked::run to
explicitly document that the lvalue overload performs a deep copy and recommend
preferring the rvalue overload to realize memory/speed savings.
- Around line 865-993: The code repeatedly dereferences features_ (e.g.,
(*features_).size(), (*features_)[i], (*features_).operator[](i)), making the
block noisy; fix it by binding a local reference (e.g., FeatureMap& features =
*features_ or auto& features = *features_) at the top of the block used in
FeatureFinderAlgorithmPicked.cpp, then replace all uses of (*features_),
(*features_)[i], and operator[] calls with features, features[i], and
features[i] respectively (update uses in startProgress, sortByMZ, size(), BB
computation loop, intersect loop, tmp population, swapFeaturesOnly, and
sortByIntensity calls).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 861ab8c4-00f5-49a2-9083-2533ac034b84

📥 Commits

Reviewing files that changed from the base of the PR and between 9d40419 and b9bfd20.

📒 Files selected for processing (4)
  • CHANGELOG
  • src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h
  • src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp
  • src/topp/FeatureFinderCentroided.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • CHANGELOG

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

please have a look at some minor comments.

Comment thread AUTHORS Resolved
Comment thread CHANGELOG Resolved
Comment on lines +128 to +129
@note This overload preserves @p input_map by copying it internally.
Use the rvalue overload with @c std::move(input_map) to avoid copying.

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.

not sure why you'd want to keep that? But ok.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the backwards compatibility. The test, Tutorial and pyopenms bindings have been adapted to the new std::move scheme. This should prevent anyone from using the inefficient function overload in the future

@cbielow
cbielow enabled auto-merge (squash) April 22, 2026 14:13
@cbielow
cbielow disabled auto-merge April 22, 2026 16:12
@cbielow
cbielow merged commit 8b81dcd into OpenMS:develop Apr 22, 2026
34 of 35 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants