Repository navigation
perf: Hot-loop cleanup in OpenSWATH scoring pipeline - #8785
Conversation
📝 WalkthroughWalkthroughThe changes optimize OpenSwath scoring by moving group-invariant pre-computations outside of parallel scoring loops, eliminating redundant calculations. Additionally, the Changes
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: 1
🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp (1)
598-615: Optional: guard pre-computations with!ms1onlyto avoid wasted work in MS1-only mode.
normalized_library_intensity,native_ids_detection, andprecursor_idsare consumed only inside the!ms1onlybranch. Computing them unconditionally before the loop adds unnecessary overhead wheneverscorePeakgroupsis called withms1only=true.♻️ Proposed guard
// Pre-compute group-invariant values (constant across all features) const bool swath_present = (!swath_maps.empty() && swath_maps[0].sptr->getNrSpectra() > 0); + std::vector<double> normalized_library_intensity; + std::vector<std::string> native_ids_detection; + std::vector<std::string> precursor_ids; + + if (!ms1only) + { - std::vector<double> normalized_library_intensity; transition_group_detection.getLibraryIntensity(normalized_library_intensity); OpenSwath::Scoring::normalize_sum(normalized_library_intensity.data(), boost::numeric_cast<int>(normalized_library_intensity.size())); - std::vector<std::string> native_ids_detection; for (Size i = 0; i < transition_group_detection.size(); i++) { native_ids_detection.push_back(transition_group_detection.getTransitions()[i].getNativeID()); } - std::vector<std::string> precursor_ids; for (Size i = 0; i < transition_group_detection.getPrecursorChromatograms().size(); i++) { precursor_ids.push_back(transition_group_detection.getPrecursorChromatograms()[i].getNativeID()); } + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp` around lines 598 - 615, Move the pre-computation of normalized_library_intensity, native_ids_detection, and precursor_ids so it only runs when ms1only is false to avoid wasted work; specifically, wrap the block that fills normalized_library_intensity (using transition_group_detection.getLibraryIntensity and OpenSwath::Scoring::normalize_sum) and the loops building native_ids_detection and precursor_ids inside the !ms1only branch in scorePeakgroups (or the caller that has the ms1only flag) and keep all references to transition_group_detection, normalized_library_intensity, native_ids_detection, and precursor_ids unchanged so the rest of the !ms1only logic uses them as before.
🤖 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/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp`:
- Around line 601-603: The call to OpenSwath::Scoring::normalize_sum currently
uses &normalized_library_intensity[0] which is undefined for an empty vector;
change the call to pass normalized_library_intensity.data() (and keep
boost::numeric_cast<int>(normalized_library_intensity.size()) for the length) so
normalize_sum receives a valid pointer even when
transition_group_detection.getLibraryIntensity produced an empty vector
(symbols: normalized_library_intensity,
transition_group_detection.getLibraryIntensity,
OpenSwath::Scoring::normalize_sum).
---
Nitpick comments:
In `@src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp`:
- Around line 598-615: Move the pre-computation of normalized_library_intensity,
native_ids_detection, and precursor_ids so it only runs when ms1only is false to
avoid wasted work; specifically, wrap the block that fills
normalized_library_intensity (using
transition_group_detection.getLibraryIntensity and
OpenSwath::Scoring::normalize_sum) and the loops building native_ids_detection
and precursor_ids inside the !ms1only branch in scorePeakgroups (or the caller
that has the ms1only flag) and keep all references to
transition_group_detection, normalized_library_intensity, native_ids_detection,
and precursor_ids unchanged so the rest of the !ms1only logic uses them as
before.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathScoring.hsrc/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cppsrc/openms/source/ANALYSIS/OPENSWATH/OpenSwathScoring.cpp
- Pass swath_maps by const& in fetchSpectrumSwath to avoid vector copy per call - Hoist group-invariant computations (swath_present, normalized_library_intensity, native_ids_detection, precursor_ids) out of the OpenMP parallel loop in scorePeakgroups, since they only depend on transition_group_detection and swath_maps which are constant across all features - Remove dead code in calculateLibraryScores: normalized_library_intensity and native_ids vectors were computed but never used Co-Authored-By: Claude Opus 4.6 <[email protected]>
d95a36c to
970f929
Compare
Summary
swath_mapsbyconst&infetchSpectrumSwath— avoids copying the entireSwathMapvector on every callscorePeakgroups()—swath_present,normalized_library_intensity,native_ids_detection, andprecursor_idsonly depend ontransition_group_detectionandswath_maps, which are constant across all featurescalculateLibraryScores—normalized_library_intensityandnative_idsvectors were computed but never readAll changes are behavior-preserving (no scoring logic modified).
Test plan
OpenSwathScoring_test— passedMRMFeatureFinderScoring_test— passedTOPP_OpenSwathWorkflow(76 tests) — 100% passed🤖 Generated with Claude Code
Summary by CodeRabbit