Repository navigation
Speed up Parquet identification I/O (single-pass metavalue write, hoisted reads) - #9689
Conversation
…es/psm_metavalues write passes and remove per-row value_slice/GetFieldByName work on read (~20-25% faster idparquet writes, output identical). Co-Authored-By: Claude Opus 4.8 <[email protected]> Claude-Session: https://claude.ai/code/session_01A7Z3YRNpFx521tmdYWib1v
67ee5aa to
3278525
Compare
|
@jonasscheid The following names might be missing from the
Please consider applying the following patch: --- AUTHORS 2026-06-30 13:09:53.121352847 +0000
+++ AUTHORS.new 2026-06-30 13:09:58.732282366 +0000
@@ -61,6 +61,7 @@
- Johannes Veit
- Johannes von Kleist
- Johan Teleman
+ - jonasscheid
- Joshua Charkow
- Juliane Schmachtenberg
- Julianus Pfeuffer |
|
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 (3)
📝 WalkthroughWalkthroughPerformance optimizations for Arrow/Parquet identification I/O: ChangesParquet I/O Performance
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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 |
|
Nice, I wonder if the whole metavalue iteration can be sped up by not doing useless roundtrips in getMetaValue. AI-review on this: The A much cheaper approach: iterate via // Before the PSM loop — one vector, lock taken at most once per unique index ever seen
std::vector<std::string> idx_to_name; // direct index by UInt, O(1) lookup
const auto& reg = MetaInfoInterface::metaRegistry();
auto cachedName = [&](UInt idx) -> const std::string& {
if (idx >= idx_to_name.size()) idx_to_name.resize(idx + 1);
if (idx_to_name[idx].empty()) idx_to_name[idx] = reg.getName(idx); // lock once per unique key
return idx_to_name[idx];
};
// In the hit loop — no vector allocation, no getMetaValue() call:
for (auto it = hit.metaBegin(); it != hit.metaEnd(); ++it)
{
const std::string& key = cachedName(it->first); // O(1), lock-free after first encounter
if (excluded_hit_mvs_psm.contains(key)) continue;
const DataValue& val = it->second; // already have it — no flat_map lookup
// ... dispatch to additional_scores / psm_metavalues
}Per-PSM cost in steady state: zero lock acquisitions, zero registry round-trips, zero This also directly unblocks future parallelisation of the export loop — the cache is local to the function, so there's no shared mutable state between threads. Ideally, the MetaInfoRegistry would support iteration so you could just build a lock-free vector-based lookup cache in a single iteration before the loop over PSMs but this is a separate improvement. |
|
Also a certain degree of parallelization should be feasible since you say that ArrowTable construction is the bottleneck. AI-review on this: Yes, this is very feasible, and Arrow's Here's the architecture: Pipeline designEach chunk is an independent The key blockers1. 2. 3. Arrow builders are not thread-safe — already fine since each worker has its own independent set of builders. 4. Rough sketch// Pre-split PSMs into batches
const size_t batch_size = 1000; // tune per row_group_size
std::vector<std::span<const PeptideIdentification>> batches = splitIntoBatches(peptide_identifications, batch_size);
// Ordered result queue
std::vector<std::future<std::shared_ptr<arrow::Table>>> futures;
futures.reserve(batches.size());
// Build each batch in parallel
// Use getKeys(UInt) to avoid registry lock contention
for (auto& batch : batches)
{
futures.push_back(std::async(std::launch::async, [&, batch]() {
return buildBatchTable(protein_identifications, batch);
}));
}
// Open FileWriter once
auto writer = openFileWriter(filename, schema, config);
// Drain futures in order -> write row groups sequentially
for (auto& fut : futures)
{
auto chunk = fut.get();
writer->WriteTable(*chunk, chunk->num_rows());
}
writer->Close();Is it worth it?From the PR's own benchmarks, the bottleneck is Arrow table construction (not I/O or compression). That's exactly the CPU-bound work you'd parallelize. For the 18k-PSM benchmark file, with batch_size=1000 you'd get ~18 parallel tasks — on a machine with ≥4 cores that should translate to roughly linear speedup for the build phase, with the writer thread never starved since construction is the bottleneck. The main caveat is the registry lock. For a metavalue-heavy file it could serialize most of the gain away. The This would be a meaningful follow-on PR — probably worth filing as an issue linked to this one rather than stacking it here. |
|
cool. I think this is good to merge... open for more optimizations |
…okup The Arrow export loops resolved per-PSM metavalues via getKeys(vector<string>) + getMetaValue(key), which takes a MetaInfoRegistry omp-critical lock twice per metavalue per PSM (getName() in getKeys, getIndex() in getMetaValue). Iterate metaBegin()/metaEnd() directly instead and resolve UInt index->name through a function-local cache, so the lock is paid at most once per unique key for the whole export. Applied to both exportToArrow and exportPSMsToQPXArrow. Iteration order is unchanged (same sorted flat_map), so output is round-trip identical. Also removes the dominant global lock that would otherwise serialize a future parallel export. Idea by Julianus Pfeuffer (PR #9689 review). Co-Authored-By: Claude Opus 4.8 <[email protected]>
…okup (#9692) The Arrow export loops resolved per-PSM metavalues via getKeys(vector<string>) + getMetaValue(key), which takes a MetaInfoRegistry omp-critical lock twice per metavalue per PSM (getName() in getKeys, getIndex() in getMetaValue). Iterate metaBegin()/metaEnd() directly instead and resolve UInt index->name through a function-local cache, so the lock is paid at most once per unique key for the whole export. Applied to both exportToArrow and exportPSMsToQPXArrow. Iteration order is unchanged (same sorted flat_map), so output is round-trip identical. Also removes the dominant global lock that would otherwise serialize a future parallel export. Idea by Julianus Pfeuffer (PR #9689 review). Co-authored-by: Claude Opus 4.8 <[email protected]>
What
Reduces the CPU cost of OpenMS's Parquet identification I/O (
QPXFile/ArrowIOHelpers), which back theidparquetformat and the PSM bundle embedded infeatureparquet/consensusparquet.Motivation:
idparquetfiles are ~10x smaller thanidXML, yet writing them was slower. Profiling showed the write cost is Arrow table construction, not compression (ZSTD is only ~11% of write time), and the per-PSM metavalue handling did redundant work.Changes
QPXFile::exportToArrow): build theadditional_scoresandpsm_metavaluescolumns in a single pass over eachPeptideHit's metavalues instead of two (they are complementary partitions of the same key set), removing a duplicategetKeys()allocation andisKnownScoreType()/getMetaValue()sweep per PSM.ArrowIOHelpers::readMetaValues): index the shared child struct viavalue_offset/value_lengthinstead ofvalue_slice(row), which allocated a sliced array per row.QPXFile::importFromArrow): hoist loop-invariantGetFieldByNamechild-array lookups (protein_accessions/additional_scores) out of the row loop.Benchmarks
idparquetwrite of a 143 MB / 18,294-PSM (metavalue-heavy) file, in-process, 9 reps:The write fix also feeds
featureparquet/consensusparquet(they embed the PSM bundle): ~6% faster feature round-trip. The read changes are correctness-neutral on this data (Arrow'svalue_sliceis near-zero-copy) but remove allocations on evidence/row-heavy inputs.Correctness
Output is round-trip identical (
idXML -> idparquet -> idXMLbyte-identical; feature/PSM counts preserved). All Arrow-IO class tests pass:QPXFile,PSMArrowIO,FeatureMapArrowIO,ConsensusMapArrowIO,ConsensusMapArrowExport,ProteinIdentificationArrowIO,ArrowIOHelpers.Summary by CodeRabbit