Skip to content

Up to 40% faster mzML reading - #8074

Merged
cbielow merged 11 commits into
OpenMS:developfrom
cbielow:mzml_meta_read
Jun 3, 2025
Merged

cbielow merged 11 commits into
OpenMS:developfrom
cbielow:mzml_meta_read

Conversation

@cbielow

@cbielow cbielow commented May 30, 2025 •

Copy link
Copy Markdown
Contributor

Description

Faster reading of mzML when additional binary data is present (e.g. for ion mobility)
- 20% faster on MSVC (318.4 MiB/s --> 399.8 MiB/s)
- 40% faster on GCC (230.7 MiB/s --> 372.2 MiB/s)

Details:
avoids checking a meta-value for every(!) data point and introduces a new case when filtering by int/mz is not required (which is usually the case), allowing to copy whole arrays instead of individual items.

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

  • New Features

    • Added a new option in FileFilter to remove all binary metadata arrays (except m/z and intensity) from spectra in mzML files.
  • Documentation

    • Updated FileFilter documentation to include new filtering options for mzML files, such as filtering by activation method, collision energy, isolation window width, zoom scans, chromatograms, metadata arrays, and empty spectra.
  • Performance Improvements

    • Optimized metadata handling for spectra, improving efficiency when processing and inserting metadata arrays.
    • Achieved 20-40% faster loading of mzML files containing additional metadata beyond m/z and intensity.
  • Refactor

    • Streamlined and clarified internal metadata merging and handling logic for better maintainability.
    • Consolidated metadata processing into a single, more efficient code path, removing redundant helper functions.
  • Tests

    • Added tests verifying meta value merging behavior, ensuring proper overwriting and addition of metadata entries.

@coderabbitai

coderabbitai Bot commented May 30, 2025 •

Copy link
Copy Markdown
Contributor
## Walkthrough

The changes remove the `addSpectrumMetaData_` method from `MzMLHandler`, refactor and optimize metadata array handling within `populateSpectraWithData_`, and introduce a compound assignment operator to `MetaInfo` for bulk metadata merging. Additionally, a new flag is added to the FileFilter tool to remove metadata arrays from spectra, and enum types in `BinaryData` are now explicitly named.

## Changes

| File(s)                                                                                   | Change Summary                                                                                                   |
|------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|
| `src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandler.h`,<br>`src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp` | Removed `addSpectrumMetaData_` method; refactored and optimized metadata handling in `populateSpectraWithData_`. |
| `src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandlerHelper.h`                          | Renamed anonymous enums in `BinaryData` struct to named enums `PRECISION` and `DATA_TYPE`.                      |
| `src/openms/include/OpenMS/METADATA/MetaInfo.h`                                          | Added `operator+=` for merging `MetaInfo` instances.                                                            |
| `src/openms/source/METADATA/MetaInfoInterface.cpp`                                       | Simplified `addMetaValues` to use the new `MetaInfo::operator+=` for bulk meta value aggregation.               |
| `src/topp/FileFilter.cpp`                                                                | Added flag to remove metadata arrays from spectra; updated documentation and processing logic accordingly.       |
| `src/openms/include/OpenMS/METADATA/MetaInfoInterface.h`                                 | Enhanced documentation comment for `addMetaValues` method clarifying overwrite behavior.                         |
| `src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp`                         | Added test coverage for `MetaInfoInterface::addMetaValues` verifying merge and overwrite behavior.               |
| `src/tests/class_tests/openms/source/MetaInfo_test.cpp`                                  | Added test coverage for `MetaInfo::operator+=` verifying merging and overwriting of meta values.                 |
| `CHANGELOG`                                                                              | Updated changelog to note 20-40% speed improvement for loading mzML files with additional metadata arrays.       |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant User
    participant FileFilter
    participant Spectrum

    User->>FileFilter: Run with --peak_options:remove_metadataarrays
    FileFilter->>Spectrum: For each spectrum, remove float, int, string arrays
    Spectrum-->>FileFilter: Spectra with only m/z and intensity arrays
    FileFilter-->>User: Output filtered mzML file

Suggested labels

Review effort 2/5

Suggested reviewers

  • jpfeuffer

Poem

In the meadow of code, a rabbit hops by,
Tidying spectra, waving metadata goodbye.
Arrays are now named, and merging’s a breeze,
With filters and flags, we do as we please.
So here’s to clean files and code running fast—
This bunny’s improvements are built to last! 🐇✨


<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 6a549b36133f614647b7bb209c33f0f875b0e888 and 77b06af6a8faf9c178be905f63ce2c6ecb90e811.

</details>

<details>
<summary>📒 Files selected for processing (5)</summary>

* `CHANGELOG` (1 hunks)
* `src/openms/include/OpenMS/METADATA/MetaInfo.h` (1 hunks)
* `src/openms/include/OpenMS/METADATA/MetaInfoInterface.h` (1 hunks)
* `src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp` (1 hunks)
* `src/tests/class_tests/openms/source/MetaInfo_test.cpp` (1 hunks)

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (2)</summary>

* CHANGELOG
* src/openms/include/OpenMS/METADATA/MetaInfoInterface.h

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* src/openms/include/OpenMS/METADATA/MetaInfo.h

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp (1)</summary><blockquote>

<details>
<summary>src/openms/include/OpenMS/METADATA/MetaInfoInterface.h (4)</summary>

* `MetaInfoInterface` (34-113)
* `MetaInfoInterface` (41-41)
* `MetaInfoInterface` (43-43)
* `MetaInfoInterface` (45-45)

</details>

</blockquote></details>

</details>

</details>

<details>
<summary>⏰ Context from checks skipped due to timeout of 90000ms (5)</summary>

* GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
* GitHub Check: build-and-test (macos-13, xcode, 14.2)
* GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
* GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
* GitHub Check: build-and-test (macos-14, xcode, 15.0.1)

</details>

<details>
<summary>🔇 Additional comments (2)</summary><blockquote>

<details>
<summary>src/tests/class_tests/openms/source/MetaInfo_test.cpp (1)</summary>

`204-218`: **Excellent test coverage for the new operator+=.**

The test comprehensively validates the merge behavior of the `operator+=` method with appropriate test cases:
- Overwriting existing keys (`"label"` value changes from "old" to "new")
- Adding new keys (`"icon"` is added)
- Preserving unrelated keys (`"exists_no_overwrite"` remains unchanged)

The test structure and assertions are well-designed and consistent with the existing test patterns in the file.

</details>
<details>
<summary>src/tests/class_tests/openms/source/MetaInfoInterface_test.cpp (1)</summary>

`330-345`: **Well-implemented test for addMetaValues method.**

The test correctly validates the `addMetaValues` functionality using the appropriate `MetaInfoInterface` API. The test structure and assertions mirror the `MetaInfo` test, ensuring consistent behavior across both the low-level `MetaInfo` class and the higher-level `MetaInfoInterface`. This provides good coverage for the meta value merging functionality at both abstraction levels.

The test appropriately verifies that `addMetaValues` merges meta information by overwriting existing keys and adding new ones while preserving unrelated values.

</details>

</blockquote></details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIAVW4w/EgAFgAGAFJIADM0RBo+ZgAvAFkAGT8SNFp4DCJoyDlIbERKRjUSL3wAd3R4ZmQCFGZefCkw2A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8JeVUNVAQ19on8piGCUCH1ncG7wTu1/YGsbnL6u9hePkOeNEAn7G9fw0/JrC1jn40op8WfV6GEIMERDh88Q9XjEKFDRdzC4kFHKEG6y2954PfYyNEAl7Zw9mfACkvBAJqR8dwFmTYGL2yFVkMeD8J4uMDebnxohmvXeFX3t4C88+dfc3rgC65N9ww5AEFlkPb5Vl4hvfOoUDUCyrZ1yqqBMHAMGChDh+yIeIYkKn718Leu8ALEFgX7bC+Ah8Jfk0ETLYI1+qAYyJvxL490R6pgg/j5jT4jgIouAMAGzFPD1ojqFSbEpEFxyAjlU/yNcGf1SEHYNgE/UcDf1f7j58We0W/rSx/5AweUGw//iwgTT8sruhHKtDR1u50dwBQuSVsxyAqwDbMKkJgPDCeQnhoGkARXCYNVyRI8BonGYNrl1ykDKkoIqgXxB1qDxq+DAvIOxiYGA9WBEginlIN4EfcpYBgC2CiHlhoBzIxbE0q53VhuwPYiPeQD7ENgqA1AAcM2MHBVEywTo6gLeDmGN5olXodALePFlzRBwQ4qortskHFC0ABAXbWgDui7YegPQ0oBgDug9Cag0gaALtlkA9A7pNQcY6MbQE1BdtvRDBaUG6AEBujLREASADuijHJBNQAgcUDuklDihxQWQEsckD3QegBANYgQGyE1AMAyxWQVIFkGlAegu2AgVICQGlC9isxqooMV2LzEVi0A0oHIFkEbGShgxR2TUKkGjE7pxQiwFkKGNEACBZxPYyUJKCzHZioAzsG0XaK3gOjsyW8OWG6KAA== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=OpenMS/OpenMS&utm_content=8074):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1122e30 and 543db5d.

📒 Files selected for processing (6)
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandler.h (0 hunks)
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandlerHelper.h (1 hunks)
  • src/openms/include/OpenMS/METADATA/MetaInfo.h (1 hunks)
  • src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp (2 hunks)
  • src/openms/source/METADATA/MetaInfoInterface.cpp (1 hunks)
  • src/topp/FileFilter.cpp (3 hunks)
💤 Files with no reviewable changes (1)
  • src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandler.h
🧰 Additional context used
🧬 Code Graph Analysis (1)
src/openms/include/OpenMS/METADATA/MetaInfo.h (1)
src/openms/source/METADATA/MetaInfoInterface.cpp (8)
  • rhs (46-68)
  • rhs (46-46)
  • rhs (71-84)
  • rhs (71-71)
  • rhs (94-117)
  • rhs (94-94)
  • rhs (119-122)
  • rhs (119-119)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: build-and-test (windows-2022, cl.exe, 14.36)
  • GitHub Check: build-and-test (ubuntu-22.04, clang++, 15)
  • GitHub Check: build-and-test (ubuntu-22.04, g++, 11)
  • GitHub Check: build-and-test (macos-14, xcode, 15.0.1)
  • GitHub Check: build-and-test (macos-13, xcode, 14.2)
🔇 Additional comments (9)
src/openms/include/OpenMS/FORMAT/HANDLERS/MzMLHandlerHelper.h (1)

47-58: Excellent improvement to type safety and code clarity.

Converting anonymous enums to named enums (PRECISION and DATA_TYPE) is a great improvement that provides:

  • Better type safety when passing these values as function parameters
  • Improved code readability and maintainability
  • Clear scoping for enum values
  • Enables better IDE support and debugging

This aligns with modern C++ best practices.

src/topp/FileFilter.cpp (3)

64-68: Well-documented feature addition.

The documentation clearly explains the new filtering capabilities including the metadata array removal feature. The formatting and placement within the existing documentation structure is consistent and appropriate.


309-309: Clear and descriptive flag registration.

The flag name remove_metadataarrays is descriptive and the help text clearly explains what data is preserved vs. removed. This follows the established naming and documentation patterns.


729-738: Efficient and correct implementation.

The implementation correctly:

  • Checks the flag before processing
  • Clears only metadata arrays (float, string, integer) while preserving m/z and intensity data
  • Operates on each spectrum in the experiment
  • Is placed appropriately after other filtering operations

The use of clear() is efficient for removing all elements from the vectors.

src/openms/source/FORMAT/HANDLERS/MzMLHandler.cpp (5)

325-327: Good optimization: Bulk metadata merging

The use of addMetaValues() for bulk metadata transfer from binary arrays to the spectrum is more efficient than individual meta value operations.


338-390: Excellent optimization: Pre-processing metadata arrays

The introduction of the MetaArrayInfo struct and pre-identification of metadata arrays is a well-designed optimization that:

  • Avoids repeated type checks during data copying
  • Pre-allocates space in spectrum arrays preventing reallocation
  • Efficiently maps input arrays to spectrum arrays

The code correctly handles all three data types (float, integer, string) and properly copies the MetaInfoDescription.


392-405: Well-optimized fast path for common case

This optimization for the most common scenario (64/32 bit precision, no metadata, no filtering) provides maximum performance by:

  • Using const iterators for efficient access
  • Avoiding any metadata handling overhead
  • Direct peak construction without intermediate steps

Good performance-oriented design.


407-477: Efficient bulk copy implementation for metadata

The bulk copy approach when filtering is not required is well-implemented:

  • Separates peak copying from metadata copying for better cache locality
  • Uses insert() with iterators for efficient bulk operations
  • Correctly handles bounds checking with std::min() at line 450
  • Properly handles all three metadata types with appropriate precision conversions

The code maintains data integrity while maximizing performance.


479-513: Correct handling of filtered peaks with metadata

The implementation for the filtered case properly:

  • Adds metadata only for peaks that pass the filter criteria
  • Includes bounds checking at lines 495, 501, and 505 to prevent array access violations
  • Handles precision conversions correctly for both float and integer metadata
  • Maintains consistency between peak data and associated metadata

This ensures data integrity when filtering is applied.

Comment on lines 250 to 261
void MetaInfoInterface::addMetaValues(const MetaInfoInterface& from)
{
std::vector<String> keys;
from.getKeys(keys);
for (String& key : keys)
if (from.meta_ == nullptr)
{
this->setMetaValue(key, from.getMetaValue(key));
return; // nothing to copy
}
if (meta_ == nullptr)
{
meta_ = new MetaInfo();
}
*meta_ += *from.meta_;
}

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.

💡 Verification agent

🧩 Analysis chain

Great optimization but verify duplicate key behavior.

The refactoring from per-key copying to bulk aggregation using operator+= is an excellent performance improvement. The lazy initialization and early return for null checks are also well implemented.

However, please verify that the new behavior with duplicate keys matches the previous implementation. The original code would have overwritten duplicate keys, while the new operator+= might preserve existing ones (depending on its implementation).

Run this script to verify the behavior:


🏁 Script executed:

#!/bin/bash
# Description: Check for existing tests of addMetaValues to understand expected duplicate key behavior

# Search for tests of addMetaValues method
rg -A 10 -B 5 "addMetaValues" --type cpp

# Look for any documentation about expected behavior
rg -A 5 -B 5 "duplicate.*key|key.*duplicate" --type cpp

Length of output: 47635


🏁 Script executed:

#!/bin/bash
# Locate the MetaInfo class definition
rg -A5 -B5 "class MetaInfo" --type h --type cpp

# Locate the operator+= implementation for MetaInfo
rg -A5 -B5 "MetaInfo::operator\\+=\\b" --type cpp

# As a fallback, search for any operator+= taking MetaInfo arguments
rg -A5 -B5 "operator\\+=.*MetaInfo" --type h --type cpp

Length of output: 7479


#!/bin/bash
# Display the MetaInfo class definition including index_to_value_
rg -A200 -B0 "class MetaInfo" --type h src/openms/include/OpenMS/METADATA/MetaInfo.h

# Show where index_to_value_ is declared
rg -A3 -B3 "index_to_value_" src/openms/include/OpenMS/METADATA/MetaInfo.h

Clarify duplicate‐key semantics in addMetaValues

The switch to bulk aggregation via

*meta_ += *from.meta_;

greatly improves performance, but MetaInfo::operator+= is defined as:

MetaInfo& operator+=(const MetaInfo& rhs)
{
  index_to_value_.insert(rhs.index_to_value_.begin(), rhs.index_to_value_.end());
  return *this;
}

std::map::insert (or equivalent) will skip any keys already in the destination, whereas the previous per-key loop would have overwritten them. Please ensure this change is intended:

• If you want source values to override on key conflict, update operator+= to assign rather than insert, for example:

for (const auto& kv : rhs.index_to_value_)
{
  index_to_value_[kv.first] = kv.second;
}

• Add a unit test for addMetaValues where destination and source share keys to lock in the desired behavior.

Locations to update/tests to add:

  • src/openms/include/OpenMS/METADATA/MetaInfo.h → operator+=
  • src/openms/source/METADATA/MetaInfoInterface.cpp → addMetaValues
  • New test file (e.g. src/tests/MetaInfo_merge_test.cpp)
🤖 Prompt for AI Agents
In src/openms/source/METADATA/MetaInfoInterface.cpp lines 250-261, the change to
use operator+= for merging meta_ maps alters duplicate key handling because
std::map::insert skips existing keys instead of overwriting them. To fix this,
modify MetaInfo::operator+= in src/openms/include/OpenMS/METADATA/MetaInfo.h to
assign values for each key from rhs to ensure source keys overwrite destination
keys. Also, add a unit test in a new file like src/tests/MetaInfo_merge_test.cpp
to verify addMetaValues correctly overwrites duplicate keys as intended.

/// If an entry with the same index/name already exists, it will be overwritten.
MetaInfo& operator+=(const MetaInfo& rhs)
{
// index_to_value_.insert(rhs.index_to_value_.begin(), rhs.index_to_value_.end()); // does not overwrite existing data

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.

Should be faster to get the underlying sorted vector , do merge sort, unique and create a flat map from it again.
Or just use a global function and insert the other way round.

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.

This is actually only a side product of this PR.
I wanted to avoid calling meta.getKeys() which is horribly inefficient, so I removed this layer.
The new code should be a lot more efficient already, although your approach is probably even faster.
For loading of mzML it does not show up as significant in perf benchmarks, so it's a bit out of scope for this PR, but might be very useful for other tools which are heavy on metadata.

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.

marked for future reference in #8076

@cbielow

cbielow commented Jun 3, 2025

Copy link
Copy Markdown
Contributor Author

ready for review/merge

@cbielow
cbielow enabled auto-merge June 3, 2025 12:16
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.

3 participants