Repository navigation
Reduced memory usage in FeatureFinderCentroided - #9159
Conversation
|
@TilBln The following names might be missing from the
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 |
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughUpdated repository metadata ( Changes
Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (4)
AUTHORSCHANGELOGsrc/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.hsrc/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp
| 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. |
There was a problem hiding this comment.
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.
| @@ -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); | |||
There was a problem hiding this comment.
coding convention :)
| 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(). |
There was a problem hiding this comment.
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(); | |||
There was a problem hiding this comment.
optional fix (since not part of the PR):
run() is private and should thus be named run_().
|
Please do a |
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (2)
src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.h (1)
128-139:⚠️ Potential issue | 🟠 MajorPublic
run(PeakMap&, …)signature hides move semantics from callers.
run()still takesPeakMap&(lvalue), but the implementation in.cppcallssetData_(std::move(input_map), …), silently invalidating the caller's map. The@notein 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'sinput_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 afterrun(...)returns. This is the root cause; the@notein 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)withfeatures[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
📒 Files selected for processing (2)
src/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.hsrc/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp
| // 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"; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cpp (1)
996-1018:⚠️ Potential issue | 🟡 MinorStill writes an out-of-range
spectrum_indexmeta value.When
RTBegin(...)returnsmap_.end(),spectrum_index == map_.size()and you correctly skipspectrum_native_idand count the case, but thespectrum_indexmeta 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 intomap_. 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: Lvaluerunoverload silently deep-copies the entirePeakMap.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 shortOPENMS_LOG_DEBUGline here, and/or emphasizing in the header note that callers who don’t need the input afterwards should prefer thePeakMap&&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
📒 Files selected for processing (4)
CHANGELOGsrc/openms/include/OpenMS/FEATUREFINDER/FeatureFinderAlgorithmPicked.hsrc/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cppsrc/topp/FeatureFinderCentroided.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
- CHANGELOG
cbielow
left a comment
There was a problem hiding this comment.
please have a look at some minor comments.
| @note This overload preserves @p input_map by copying it internally. | ||
| Use the rvalue overload with @c std::move(input_map) to avoid copying. |
There was a problem hiding this comment.
not sure why you'd want to keep that? But ok.
There was a problem hiding this comment.
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
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]>
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)
----- 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
How can I get additional information on failed tests during CI
Click to expand
If your PR is failing you can check outIf you click in the column that lists the failed tests you will get detailed error messages.
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.rebuild jenkinswill retrigger Jenkins-based CI buildsSummary by CodeRabbit
Performance
Improvements
Documentation
Chore