Repository navigation
fix(Feature): eliminate cache-invalidation side effect in getConvexHulls() - #9404
timosachsenberg wants to merge 4 commits into
Conversation
…lls() The non-const getConvexHulls() unconditionally set convex_hulls_modified_ = true, causing unnecessary recomputation of the overall convex hull on every subsequent getConvexHull() call — even when callers only read. Due to C++ overload resolution, ~20 read-only call sites in hot paths (feature finding, scoring, ID mapping) triggered this side effect simply because they held a non-const Feature reference. Replace the non-const overload with explicit mutation methods: - addConvexHull(): for push_back use cases - clearConvexHulls(): for clear use cases - getMutableConvexHulls(): for complex direct-access mutation Read-only callers now automatically resolve to the const overload, which does not touch the dirty flag. https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
After removing the non-const getConvexHulls() overload, vector<ConvexHull2D>::iterator no longer compiles because the const overload returns const_iterator from begin()/end(). Both loop bodies were already read-only. https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
Register the new methods in the test000 Feature docstring and add a small round-trip test exercising addConvexHull and clearConvexHulls through the nanobind binding. https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
|
@timosachsenberg The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-05-25 10:15:30.094870070 +0000
+++ AUTHORS.new 2026-05-25 10:15:35.109830403 +0000
@@ -23,6 +23,7 @@
- Chris Bauer
- Chris Bielow
- Christian Ehrlich
+ - Claude
- Clemens Groepl
- Cornelia Friedle
- Daniel Jameson |
|
Caution Review failedPull request was closed or merged during review No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (5)
💤 Files with no reviewable changes (1)
📝 WalkthroughWalkthroughThe PR refactors the ChangesFeature convex hull API refactoring
Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/tests/class_tests/openms/source/Feature_test.cpp (1)
101-113:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winExercise
getMutableConvexHulls()in this test section.This section is named for
getMutableConvexHulls(), but it only reads throughgetConvexHulls(). As written, it does not test the mutable accessor path at all.Suggested test adjustment
START_SECTION((vector<ConvexHull2D>& getMutableConvexHulls())) Feature tmp; tmp.setConvexHulls(hulls); - TEST_EQUAL(tmp.getConvexHulls().size(),2) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][0],1.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[0][1],2.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][0],3.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[0].getHullPoints()[1][1],4.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][0],0.5) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[0][1],0.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][0],1.0) - TEST_REAL_SIMILAR(tmp.getConvexHulls()[1].getHullPoints()[1][1],1.0) + auto& mutable_hulls = tmp.getMutableConvexHulls(); + TEST_EQUAL(mutable_hulls.size(),2) + TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[0][0],1.0) + TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[0][1],2.0) + TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[1][0],3.0) + TEST_REAL_SIMILAR(mutable_hulls[0].getHullPoints()[1][1],4.0) + TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[0][0],0.5) + TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[0][1],0.0) + TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[1][0],1.0) + TEST_REAL_SIMILAR(mutable_hulls[1].getHullPoints()[1][1],1.0) END_SECTION🤖 Prompt for 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. In `@src/tests/class_tests/openms/source/Feature_test.cpp` around lines 101 - 113, The test is supposed to exercise getMutableConvexHulls() but only calls getConvexHulls(); change the test to call tmp.getMutableConvexHulls(), mutate one of the hull points (for example modify hull 0 point 0 x/y), then assert the mutation is visible through tmp.getConvexHulls() (or a subsequent getMutableConvexHulls() call); keep the existing setConvexHulls(hulls) and other value checks but add a mutation via getMutableConvexHulls() on the Feature instance to verify the mutable accessor works.
🤖 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/include/OpenMS/KERNEL/Feature.h`:
- Around line 89-96: Replace the short "///" comments for the four new public
methods with full Doxygen blocks: add a /** */ comment for
getMutableConvexHulls() that includes `@brief`, `@return` (reference to vector of
ConvexHull2D) and `@note` that it marks the cache dirty; for setConvexHulls(const
std::vector<ConvexHull2D>& hulls) include `@brief` and `@param` [in] hulls; for
addConvexHull(const ConvexHull2D& hull) include `@brief` and `@param` [in] hull; for
clearConvexHulls() include `@brief` and `@note` if it invalidates cached data;
include `@throws` only if the method can throw, otherwise omit, following the
project's documentation conventions and using the exact symbol names
getMutableConvexHulls, setConvexHulls, addConvexHull, clearConvexHulls.
---
Outside diff comments:
In `@src/tests/class_tests/openms/source/Feature_test.cpp`:
- Around line 101-113: The test is supposed to exercise getMutableConvexHulls()
but only calls getConvexHulls(); change the test to call
tmp.getMutableConvexHulls(), mutate one of the hull points (for example modify
hull 0 point 0 x/y), then assert the mutation is visible through
tmp.getConvexHulls() (or a subsequent getMutableConvexHulls() call); keep the
existing setConvexHulls(hulls) and other value checks but add a mutation via
getMutableConvexHulls() on the Feature instance to verify the mutable accessor
works.
🪄 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: 5bb22e8c-92c4-4d47-80cb-306fcf717a9b
📒 Files selected for processing (26)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/MRMTransitionGroupPicker.hsrc/openms/include/OpenMS/KERNEL/Feature.hsrc/openms/source/ANALYSIS/ID/IDMapper.cppsrc/openms/source/ANALYSIS/MAPMATCHING/MapAlignmentTransformer.cppsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/FEATUREFINDER/Biosaur2Algorithm.cppsrc/openms/source/FEATUREFINDER/FeatureFinderAlgorithmMetaboIdent.cppsrc/openms/source/FEATUREFINDER/FeatureFinderAlgorithmPicked.cppsrc/openms/source/FEATUREFINDER/FeatureFinderIdentificationAlgorithm.cppsrc/openms/source/FEATUREFINDER/FeatureFinderMultiplexAlgorithm.cppsrc/openms/source/FORMAT/FeatureMapArrowIO.cppsrc/openms/source/FORMAT/HANDLERS/FeatureXMLHandler.cppsrc/openms/source/FORMAT/OMSFileLoad.cppsrc/openms/source/KERNEL/Feature.cppsrc/pyOpenMS/bindings/bind_kernel.cppsrc/pyOpenMS/tests/unittests/test000.pysrc/pyOpenMS/tests/unittests/test_IDMapper.pysrc/tests/class_tests/openms/source/FeatureMapArrowIO_test.cppsrc/tests/class_tests/openms/source/Feature_test.cppsrc/tests/class_tests/openms/source/OpenSwathMRMFeatureAccessOpenMS_test.cppsrc/tests/class_tests/openms/source/OpenSwathTestHelper.hsrc/topp/FeatureFinderCentroided.cppsrc/topp/FeatureLinkerBase.cppsrc/topp/FileFilter.cppsrc/topp/MRMTransitionGroupPicker.cppsrc/topp/MassTraceExtractor.cpp
| /// Mutable access to the convex hulls (marks cache as dirty) | ||
| std::vector<ConvexHull2D>& getMutableConvexHulls(); | ||
| /// Set the convex hulls of single mass traces | ||
| void setConvexHulls(const std::vector<ConvexHull2D>& hulls); | ||
| /// Add a single convex hull | ||
| void addConvexHull(const ConvexHull2D& hull); | ||
| /// Remove all convex hulls | ||
| void clearConvexHulls(); |
There was a problem hiding this comment.
Add full Doxygen blocks for the new public convex-hull methods.
The new declarations currently use short /// comments only. For this header path, new public methods should include full /** */ docs with @brief, parameter direction tags (for hull), @return (for getMutableConvexHulls()), and @throws/@note where relevant.
📘 Proposed documentation update
- /// Mutable access to the convex hulls (marks cache as dirty)
- std::vector<ConvexHull2D>& getMutableConvexHulls();
+ /**
+ `@brief` Mutable access to mass-trace convex hulls
+ `@return` Reference to the internal convex hull container
+ `@note` Marks the overall convex hull cache as dirty.
+ */
+ std::vector<ConvexHull2D>& getMutableConvexHulls();
@@
- /// Add a single convex hull
- void addConvexHull(const ConvexHull2D& hull);
+ /**
+ `@brief` Add one mass-trace convex hull
+ `@param`[in] hull Convex hull to append
+ `@note` Marks the overall convex hull cache as dirty.
+ */
+ void addConvexHull(const ConvexHull2D& hull);
@@
- /// Remove all convex hulls
- void clearConvexHulls();
+ /**
+ `@brief` Remove all mass-trace convex hulls
+ `@note` Marks the overall convex hull cache as dirty.
+ */
+ void clearConvexHulls();As per coding guidelines: “src/openms/include/OpenMS/**/*.h: Method documentation must include @brief, parameter documentation with [in], [out], or [in,out], @return, @throws, and @note/@warning.”
🤖 Prompt for 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.
In `@src/openms/include/OpenMS/KERNEL/Feature.h` around lines 89 - 96, Replace the
short "///" comments for the four new public methods with full Doxygen blocks:
add a /** */ comment for getMutableConvexHulls() that includes `@brief`, `@return`
(reference to vector of ConvexHull2D) and `@note` that it marks the cache dirty;
for setConvexHulls(const std::vector<ConvexHull2D>& hulls) include `@brief` and
`@param` [in] hulls; for addConvexHull(const ConvexHull2D& hull) include `@brief`
and `@param` [in] hull; for clearConvexHulls() include `@brief` and `@note` if it
invalidates cached data; include `@throws` only if the method can throw, otherwise
omit, following the project's documentation conventions and using the exact
symbol names getMutableConvexHulls, setConvexHulls, addConvexHull,
clearConvexHulls.
The cached overall convex hull (convex_hull_, convex_hulls_modified_) existed to avoid recomputing a bounding box from mass trace hulls. The computation is trivial — iterate ~1-5 hulls and enlarge a DBoundingBox — so the cache added complexity for near-zero benefit. Changes: - Remove mutable members convex_hull_ and convex_hulls_modified_ - getConvexHull() now computes and returns by value each time - Simplify constructors, copy/move operators, and mutators - Remove no-op expandToBoundingBox() on overall hull in FeatureFinderCentroided (the overall hull is already a bounding box) - Update pyOpenMS binding to return by value This eliminates all mutable state from Feature related to convex hulls, making the class simpler and thread-safer. https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
The non-const getConvexHulls() unconditionally set convex_hulls_modified_
= true, causing unnecessary recomputation of the overall convex hull on
every subsequent getConvexHull() call — even when callers only read. Due
to C++ overload resolution, ~20 read-only call sites in hot paths
(feature finding, scoring, ID mapping) triggered this side effect simply
because they held a non-const Feature reference.
Replace the non-const overload with explicit mutation methods:
Read-only callers now automatically resolve to the const overload,
which does not touch the dirty flag.
https://claude.ai/code/session_01YadC62yRF8dsQHHF8kebe2
Summary by CodeRabbit