Skip to content

Stream QPX feature Parquet export in batches to bound peak memory - #9698

Merged
timosachsenberg merged 2 commits into
developfrom
perf/qpx-feature-streaming-export
Jul 1, 2026
Merged

timosachsenberg merged 2 commits into
developfrom
perf/qpx-feature-streaming-export

Conversation

@timosachsenberg

@timosachsenberg timosachsenberg commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

IsobaricWorkflow writes three QPX Parquet files in order: quantms.feature.parquet (via ConsensusMapArrowExport), then quantms.psm.parquet, then quantms.pg.parquet.

For isobaric labeling there is ~one consensus feature per PSM, so the feature table can be millions of rows. The old ConsensusMapArrowExport::exportToArrow built the entire Arrow table in memory before a single write, so on large runs peak memory drove the process into swap/OOM — and because the feature file is written first, quantms.feature.parquet was never created at all (the run died before any file hit disk).

#9697 already fixed the equivalent problem for the PSM export (QPXFile::exportToParquetStreaming). This PR ports the same pattern to the feature export, serial only.

What this does

  • Refactor the per-row build into an anonymous-namespace range builder buildFeatureTableRange(cmap, id_lut, [begin, end)); hoist the per-map protein-group/gene lookups into buildFeatureIdLookups and the Parquet writer-property setup into makeFeatureWriterProperties. Each feature row is independent (no cross-row state), so any contiguous sub-range yields a self-contained, schema-valid table.
  • exportToArrow() now delegates over the whole range [0, size()) — output unchanged.
  • Add exportToParquetStreaming(cmap, filename, batch_size, config): build and flush one batch_size-sized range at a time through a persistent parquet::arrow::FileWriter, so peak memory stays bounded by one batch instead of the whole ~N-row table.
  • IsobaricWorkflow uses the streaming path for the feature export.

The written rows and their order are identical to the one-shot path; only the Parquet row-group layout may differ.

Scope

  • Feature export only. The pg export builds one row per indistinguishable protein group (bounded by protein count, not per-PSM), so it is not a memory risk and is intentionally left unchanged.
  • Serial only. The per-feature build touches ProForma/modifications/MetaInfoRegistry; an OpenMP parallel build (as in Speed up & bound memory of QPX PSM Parquet export (streaming + parallel build) #9697's PSM path) is deliberately out of scope here and can be a follow-up.

Tests

ConsensusMapArrowExport_test extended with a streaming↔one-shot equivalence section: full Table::Equals over combined chunks (covers nested/list + lookup-derived columns), made order-sensitive via a unique per-feature RT, across multiple batches, the single-batch and batch_size == 0 cases, and the empty-map edge. All ConsensusMapArrowExport class tests pass locally.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HcY3LMYuUDF2psYat9uUYN

Summary by CodeRabbit

  • New Features

    • Added streaming Parquet export for consensus map data to support large outputs with bounded peak memory.
    • Updated the isobaric workflow QPX feature-level export to use the new streaming Parquet mode.
  • Bug Fixes

    • Improved edge-case behavior for streaming exports, including empty maps and batch size handling (including zero and oversized batch sizes).
    • Ensured streaming and non-streaming Parquet exports remain row- and content-consistent on round-trip.
  • Tests

    • Added Parquet round-trip coverage to validate streaming output across key column sets and scenarios.

For isobaric labeling there is ~one consensus feature per PSM, so the
ConsensusMap feature table can be millions of rows. The old
ConsensusMapArrowExport::exportToArrow built the entire Arrow table in
memory before a single write, so on large runs peak memory drove the
process into swap/OOM and quantms.feature.parquet was never created
(it is written first in IsobaricWorkflow, before the PSM/pg exports).

Port the streaming approach already used for the PSM export (#9697) to
the feature export, serial only:

- Refactor the per-row build into an anonymous-namespace range builder
  buildFeatureTableRange(cmap, id_lut, [begin, end)); hoist the per-map
  protein-group/gene lookups into buildFeatureIdLookups and the Parquet
  writer properties into makeFeatureWriterProperties. Each feature row is
  independent, so any contiguous sub-range yields a self-contained,
  schema-valid table.
- exportToArrow() now delegates over the whole range (output unchanged).
- Add exportToParquetStreaming(): build and flush one batch_size-sized
  range at a time through a persistent parquet::arrow::FileWriter, so
  peak memory stays bounded by one batch instead of the whole table.
- IsobaricWorkflow uses the streaming path for the feature export.

Written rows and their order are identical to the one-shot path; only
the Parquet row-group layout may differ. A new class-test asserts
streaming<->one-shot equivalence (full Table::Equals over combined
chunks, order-sensitive via unique RT) across multiple batches, the
single-batch and batch_size==0 cases, and the empty-map edge.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HcY3LMYuUDF2psYat9uUYN
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a917e831-73c4-4515-be0d-4bae0fb1dea0

📥 Commits

Reviewing files that changed from the base of the PR and between 857947e and 4c3820a.

📒 Files selected for processing (1)
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp

📝 Walkthrough

Walkthrough

Adds a new exportToParquetStreaming API to ConsensusMapArrowExport, refactors shared range-based Arrow table construction and lookup setup, validates the new path with readback tests, and switches IsobaricWorkflow to use streaming export.

Changes

Streaming Parquet Export

Layer / File(s) Summary
Streaming export API declaration
src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h
Declares exportToParquetStreaming with batch_size and ParquetWriteConfig parameters, documented as row/order-equivalent to exportToParquet.
Shared lookup and writer-property helpers
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
Adds FeatureIdLookups/buildFeatureIdLookups() for protein-group q-value and gene lookups, makeFeatureWriterProperties() for writer config, and a buildFeatureTableRange() interface, plus an <algorithm> include.
Range-based Arrow table construction
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
Updates capacity reservation, lookup references, and feature iteration to operate over an explicit [range_begin, range_end) slice instead of the whole map.
exportToArrow / exportToParquet refactor
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
exportToArrow delegates to the shared range builder over the full map; exportToParquet uses the centralized writer-properties helper.
exportToParquetStreaming implementation
src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
Precomputes lookups and schema once, streams batches through a single FileWriter, guards batch_size == 0, handles zero-row maps, and folds close failures into the return status.
Streaming export tests
src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
Adds Arrow/Parquet readback headers and a read_combined helper, builds a 2500-row synthetic ConsensusMap, and validates streaming output against a non-streaming reference for row counts, column equality, and edge cases.
IsobaricWorkflow caller update
src/topp/IsobaricWorkflow.cpp
Switches feature-level Parquet export to exportToParquetStreaming while preserving existing error handling.

Sequence Diagram(s)

sequenceDiagram
    participant IsobaricWorkflow
    participant ConsensusMapArrowExport
    participant buildFeatureIdLookups
    participant buildFeatureTableRange
    participant ParquetFileWriter

    IsobaricWorkflow->>ConsensusMapArrowExport: exportToParquetStreaming(cmap, filename, batch_size, config)
    ConsensusMapArrowExport->>buildFeatureIdLookups: buildFeatureIdLookups(cmap)
    buildFeatureIdLookups-->>ConsensusMapArrowExport: lookup tables
    ConsensusMapArrowExport->>ParquetFileWriter: open(filename, schema, writer_props)
    loop each batch [b, e)
        ConsensusMapArrowExport->>buildFeatureTableRange: buildFeatureTableRange(cmap, id_lut, b, e)
        buildFeatureTableRange-->>ConsensusMapArrowExport: Arrow table batch
        ConsensusMapArrowExport->>ParquetFileWriter: WriteTable(batch)
    end
    ConsensusMapArrowExport->>ParquetFileWriter: Close()
    ParquetFileWriter-->>ConsensusMapArrowExport: close status
    ConsensusMapArrowExport-->>IsobaricWorkflow: ok / failure
Loading

Suggested reviewers: jpfeuffer

Poem

A hop, a batch, a table small,
No more one giant memory hall!
Rows stream out in tidy rows,
And Parquet hums as the carrot grows. 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: batched streaming of feature Parquet export to reduce peak memory.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/qpx-feature-streaming-export

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.

@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 (3)
src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h (1)

90-90: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Size for the public batch-size parameter.

batch_size is a feature count, so the public OpenMS API should use Size instead of size_t; mirror the same change in the .cpp definition and helper counters. As per coding guidelines, “Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types.”

Proposed fix
-    size_t batch_size = 1000000,
+    Size batch_size = 1000000,
🤖 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/FORMAT/ConsensusMapArrowExport.h` at line 90, The
public batch-size API in ConsensusMapArrowExport should use OpenMS::Size instead
of size_t. Update the ConsensusMapArrowExport declaration, the matching .cpp
definition, and any related helper counters or loop variables that represent
feature counts to use Size consistently. Keep the symbol names aligned with the
existing export path so the public interface and implementation both follow the
OpenMS primitive type guideline from OpenMS/CONCEPT/Types.h.

Source: Coding guidelines

src/openms/source/FORMAT/ConsensusMapArrowExport.cpp (2)

133-137: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use Size for feature ranges and batch counters.

These values index ConsensusMap rows and represent OpenMS container sizes; use Size consistently instead of size_t. As per coding guidelines, “Use OpenMS primitive types from OpenMS/CONCEPT/Types.h instead of standard C++ types.”

Proposed fix
 std::shared_ptr<arrow::Table> buildFeatureTableRange(
   const ConsensusMap& cmap,
   const FeatureIdLookups& id_lut,
-  size_t range_begin,
-  size_t range_end)
+  Size range_begin,
+  Size range_end)
@@
-  for (size_t feat_idx = range_begin; feat_idx < range_end; ++feat_idx)
+  for (Size feat_idx = range_begin; feat_idx < range_end; ++feat_idx)
@@
 bool ConsensusMapArrowExport::exportToParquetStreaming(
   const ConsensusMap& cmap,
   const std::string& filename,
-  size_t batch_size,
+  Size batch_size,
   const ParquetWriteConfig& config)
@@
-  const size_t N = cmap.size();
+  const Size N = cmap.size();
@@
-    for (size_t b = 0; b < N && ok; b += batch_size)
+    for (Size b = 0; b < N && ok; b += batch_size)

Also applies to: 293-293, 339-341, 969-973, 1029-1038

🤖 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/source/FORMAT/ConsensusMapArrowExport.cpp` around lines 133 - 137,
Use OpenMS Size consistently for feature range indices and batch counters
instead of size_t. Update buildFeatureTableRange and the related code paths in
ConsensusMapArrowExport to use Size for ConsensusMap row indexing and
container-sized values, and ensure any loop counters or range parameters in the
referenced export helpers follow the same OpenMS type convention from
OpenMS/CONCEPT/Types.h.

Source: Coding guidelines


987-988: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Avoid flushing logs with std::endl.

Use "\n" in the new logging paths to avoid unnecessary flushes. As per coding guidelines, “Avoid std::endl and use \n instead for performance reasons.”

Proposed fix
-    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open " << filename << " for writing: "
-                     << file_result.status().ToString() << std::endl;
+    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open " << filename << " for writing: "
+                     << file_result.status().ToString() << "\n";
@@
-    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open Parquet writer for " << filename << ": "
-                     << writer_result.status().ToString() << std::endl;
+    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to open Parquet writer for " << filename << ": "
+                     << writer_result.status().ToString() << "\n";
@@
-      OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to build feature batch [" << b << ", " << e << ")" << std::endl;
+      OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to build feature batch [" << b << ", " << e << ")" << "\n";
@@
-      OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to write feature batch to " << filename << ": "
-                       << st.ToString() << std::endl;
+      OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to write feature batch to " << filename << ": "
+                       << st.ToString() << "\n";
@@
-    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close Parquet writer for " << filename << ": "
-                     << writer_close.ToString() << std::endl;
+    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close Parquet writer for " << filename << ": "
+                     << writer_close.ToString() << "\n";
@@
-    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close output stream for " << filename << ": "
-                     << outfile_close.ToString() << std::endl;
+    OPENMS_LOG_ERROR << "ConsensusMapArrowExport: Failed to close output stream for " << filename << ": "
+                     << outfile_close.ToString() << "\n";

Also applies to: 1000-1001, 1015-1015, 1021-1022, 1046-1047, 1053-1054

🤖 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/source/FORMAT/ConsensusMapArrowExport.cpp` around lines 987 - 988,
The logging in ConsensusMapArrowExport still uses std::endl in several error
paths, which should be replaced with "\n" to avoid unnecessary flushes. Update
the affected OPENMS_LOG_ERROR statements in ConsensusMapArrowExport (including
the file-open failure path and the other listed logging sites) to end with "\n"
instead of std::endl while keeping the existing message text and context intact.

Source: Coding guidelines

🤖 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/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp`:
- Around line 439-509: Replace the boolean assertions in
ConsensusMapArrowExport_test.cpp with the dedicated macros: in the
ConsensusMapArrowExport streaming and empty-map test cases, change every
TEST_EQUAL(..., true) to TEST_TRUE(...) and any TEST_EQUAL(..., false) to
TEST_FALSE(...). Keep the same expressions and surrounding checks, and update
the representative assertions around exportToParquetStreaming, read_combined,
all_eq, File::exists, and Equals so the test follows the project’s boolean
assertion style.

---

Nitpick comments:
In `@src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h`:
- Line 90: The public batch-size API in ConsensusMapArrowExport should use
OpenMS::Size instead of size_t. Update the ConsensusMapArrowExport declaration,
the matching .cpp definition, and any related helper counters or loop variables
that represent feature counts to use Size consistently. Keep the symbol names
aligned with the existing export path so the public interface and implementation
both follow the OpenMS primitive type guideline from OpenMS/CONCEPT/Types.h.

In `@src/openms/source/FORMAT/ConsensusMapArrowExport.cpp`:
- Around line 133-137: Use OpenMS Size consistently for feature range indices
and batch counters instead of size_t. Update buildFeatureTableRange and the
related code paths in ConsensusMapArrowExport to use Size for ConsensusMap row
indexing and container-sized values, and ensure any loop counters or range
parameters in the referenced export helpers follow the same OpenMS type
convention from OpenMS/CONCEPT/Types.h.
- Around line 987-988: The logging in ConsensusMapArrowExport still uses
std::endl in several error paths, which should be replaced with "\n" to avoid
unnecessary flushes. Update the affected OPENMS_LOG_ERROR statements in
ConsensusMapArrowExport (including the file-open failure path and the other
listed logging sites) to end with "\n" instead of std::endl while keeping the
existing message text and context intact.
🪄 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: c8c7f691-29fe-41ba-839c-a222ea3774e8

📥 Commits

Reviewing files that changed from the base of the PR and between f6ffb57 and 857947e.

📒 Files selected for processing (4)
  • src/openms/include/OpenMS/FORMAT/ConsensusMapArrowExport.h
  • src/openms/source/FORMAT/ConsensusMapArrowExport.cpp
  • src/tests/class_tests/openms/source/ConsensusMapArrowExport_test.cpp
  • src/topp/IsobaricWorkflow.cpp

…st.cpp

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@timosachsenberg
timosachsenberg merged commit 0fe9ffb into develop Jul 1, 2026
9 checks passed
@timosachsenberg
timosachsenberg deleted the perf/qpx-feature-streaming-export branch July 1, 2026 17:52
timosachsenberg added a commit that referenced this pull request Jul 2, 2026
Three recently merged PRs landed on develop without changelog coverage:
the PeptideIdentification::base_name removal (breaking API change routed
through the run-level primary MS run path) and the two QPX Parquet
streaming-export performance fixes (PSM export in #9697, feature export
in #9698) that bound peak memory for large isobaric-labeling runs.


Claude-Session: https://claude.ai/code/session_0167xb6udbdqvWLcUsNeZf4r

Co-authored-by: Claude <[email protected]>
timosachsenberg added a commit that referenced this pull request Jul 4, 2026
Routine changelog sweep found three merged develop PRs without changelog
coverage: FileInfo progress-logging restoration (#9707), a pyOpenMS enum
binding completeness fix (#9705), and OpenMP parallelization of the QPX
feature Parquet export (#9699, extending #9698). Also updated the #9698
entry's now-inaccurate "Serial only" note to point at #9699.


Claude-Session: https://claude.ai/code/session_014CUTttkkvRtTRtiV8ctAM6

Co-authored-by: Claude <[email protected]>
timosachsenberg added a commit that referenced this pull request Jul 6, 2026
Three recently merged PRs landed on develop without changelog coverage:
the OpenMP parallelization of the QPX feature Parquet export (#9699,
follow-up to #9698), the pyOpenMS enum-binding drift fix restoring
several inaccessible NASFragmentType/ProteomicsPkaScale/OSWHierarchy/
LPWrapper::SOLVER enumerators (#9705), and the re-added FileInfo
progress logging exposed to pyOpenMS via Options.log_type (#9707).


Claude-Session: https://claude.ai/code/session_01YCkM79JUnodCGEHtBKNWSz

Co-authored-by: Claude <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[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