Skip to content

perf: Hot-loop cleanup in OpenSWATH scoring pipeline - #8785

Merged
timosachsenberg merged 1 commit into
developfrom
feature/openswath-hot-loop-cleanup
Feb 23, 2026
Merged

timosachsenberg merged 1 commit into
developfrom
feature/openswath-hot-loop-cleanup

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Feb 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pass swath_maps by const& in fetchSpectrumSwath — avoids copying the entire SwathMap vector on every call
  • Hoist group-invariant computations out of the OpenMP parallel loop in scorePeakgroups() — swath_present, normalized_library_intensity, native_ids_detection, and precursor_ids 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 read

All changes are behavior-preserving (no scoring logic modified).

Test plan

  • OpenSwathScoring_test — passed
  • MRMFeatureFinderScoring_test — passed
  • TOPP_OpenSwathWorkflow (76 tests) — 100% passed

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Optimized internal spectrum scoring computation by pre-calculating repeated values and eliminating redundant recalculations during batch processing.

@coderabbitai

coderabbitai Bot commented Feb 23, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

The changes optimize OpenSwath scoring by moving group-invariant pre-computations outside of parallel scoring loops, eliminating redundant calculations. Additionally, the fetchSpectrumSwath method signature is updated to accept SWATH maps as const references, improving const-correctness.

Changes

Cohort / File(s) Summary
Method Signature Update
src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathScoring.h, src/openms/source/ANALYSIS/OPENSWATH/OpenSwathScoring.cpp
Updated fetchSpectrumSwath method to accept swath_maps parameter as const reference instead of by value.
Scoring Optimization
src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
Moved group-invariant pre-computations (swath_present flag, normalized library intensity, native_ids, and precursor_ids) outside of parallel scoring block to eliminate redundant per-feature re-calculations.
DIA Scoring Cleanup
src/openms/source/ANALYSIS/OPENSWATH/OpenSwathScoring.cpp
Removed intermediate vector preparation (normalized_library_intensity and native_ids) from calculateDIAScores method.

Poem

🐰 Hops with delight through optimized code,
Const references smooth the scoring load,
Loop invariants now computed once, not twice,
Performance blooms—faster scoring vice!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 captures the main optimization: parameter passing improvement and hot-loop cleanup in the OpenSWATH scoring pipeline to improve performance.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/openswath-hot-loop-cleanup

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: 1

🧹 Nitpick comments (1)
src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp (1)

598-615: Optional: guard pre-computations with !ms1only to avoid wasted work in MS1-only mode.

normalized_library_intensity, native_ids_detection, and precursor_ids are consumed only inside the !ms1only branch. Computing them unconditionally before the loop adds unnecessary overhead whenever scorePeakgroups is called with ms1only=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

📥 Commits

Reviewing files that changed from the base of the PR and between f1cf941 and d95a36c.

📒 Files selected for processing (3)
  • src/openms/include/OpenMS/ANALYSIS/OPENSWATH/OpenSwathScoring.h
  • src/openms/source/ANALYSIS/OPENSWATH/MRMFeatureFinderScoring.cpp
  • src/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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant