Refactored multicore summarisation to distribute pre-split data - #215
Refactored multicore summarisation to distribute pre-split data#215tonywu1999 wants to merge 1 commit into
Conversation
* MSstatsSummarizeWithMultipleCores: replaced `protein_indices = split(seq_len(nrow(input)), ...)` (each worker re-indexed into the broadcast `input`) with `protein_data = split(input, ...)` so each worker receives only its own protein's rows. Dropped `input` and `protein_indices` from clusterExport accordingly. * Removed the per-100-proteins progress log inside the worker function — counting completed proteins under parLapply without coordination is unreliable; the startup "Number of proteins to process: N" cat is sufficient. * Fixed an undefined-variable regression on the same change path: `num_proteins = length(protein_indices)` would have thrown `object 'protein_indices' not found` on the first multicore invocation. Now reads `length(protein_data)`. * Added inst/tinytest/test_dataProcess.R multicore-parity block asserting single-core and multi-core linear ProteinLevelData agree on row count, protein set, LogIntensities, and Variance. * Added benchmark/profile_dataprocess_peak.R that drives dataProcess() under profmem::profmem() and reports peak RSS via ps::ps_memory_info(). * DESCRIPTION: added callr, ps, profmem to Suggests so the benchmark script is runnable with a checkout. None become hard dependencies. See MSstats-ai/todos/active/TODO-MS-20260514_fix-memory-bugs.md Co-Authored-By: Claude <noreply@anthropic.com>
📝 WalkthroughWalkthroughMulticore protein summarization now pre-splits data before worker execution. A linear-summary parity test was added, and a standalone benchmark replays ChangesData processing and profiling
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
|
Failed to generate code suggestions for PR |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 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 `@benchmark/profile_dataprocess_peak.R`:
- Around line 115-122: The checkpoint function currently reports only R Vcells
usage and must collect the promised broader memory metrics. Update checkpoint
and its stage instrumentation to record process RSS via ps and largest
allocations via profmem, using callr where isolation or monitoring is needed;
otherwise narrow the script’s peak-memory claims to Vcells only.
In `@inst/tinytest/test_dataProcess.R`:
- Around line 126-148: Update the comparison block after sorting linear_single
and linear_multi to assert matching as.character(RUN) values alongside Protein
before comparing LogIntensities or Variance; when LABEL exists in both
summaries, assert matching LABEL values as well. Keep the existing ordering and
numeric comparisons unchanged.
In `@R/dataProcess.R`:
- Around line 240-253: Register an on.exit cleanup immediately after creating
the cluster used by the summarized_results parallel branches, ensuring
parallel::stopCluster(cl) runs even when either parallel::parLapply call fails.
Preserve the existing successful execution and outer tryCatch behavior.
- Around line 246-252: Update both the parallel `MSstatsSummarizeSingleLinear`
call inside `parallel::parLapply` and the single-core call in the same
data-processing flow to forward the exported `equal_variance` value as the
summarizer’s `equalFeatureVar` argument. Add coverage exercising
`equalFeatureVar = FALSE` and confirming matching behavior between parallel and
single-core paths.
🪄 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: 427804df-b1e5-4276-b082-a0e322d5ee83
📒 Files selected for processing (4)
DESCRIPTIONR/dataProcess.Rbenchmark/profile_dataprocess_peak.Rinst/tinytest/test_dataProcess.R
|
Tested this on Selevsek-2015-Spectronaut dataset and monitored memory usage with Original parallelization (both commit ID f5259ee, 3fa0bd1) Parallelization from this PR: Here, the 2nd process doesn't get opened for a long time (opens 12 minutes later), and the first process While the approach seems to ensure the input object isn't copied across workers, the practical implications suggest |
|
My recommendation is to close this PR, I don't think this is the right approach for parallelization. People have been complaining about parallelization crashing due to memory spikes. I believe these memory spikes are confounded with memory spikes from MSstatsBalancedDesign, so we need to think more about this. The parallelization may actually not be broken. |
protein_indices = split(seq_len(nrow(input)), ...)(each worker re-indexed into the broadcastinput) withprotein_data = split(input, ...)so each worker receives only its own protein's rows. Droppedinputandprotein_indicesfrom clusterExport accordingly.num_proteins = length(protein_indices)would have thrownobject 'protein_indices' not foundon the first multicore invocation. Now readslength(protein_data).See MSstats-ai/todos/active/TODO-MS-20260514_fix-memory-bugs.md
Motivation and Context
Please include relevant motivation and context of the problem along with a short summary of the solution.
Changes
Please provide a detailed bullet point list of your changes.
Testing
Please describe any unit tests you added or modified to verify your changes.
Checklist Before Requesting a Review
Motivation and context
Multicore summarisation previously broadcast the full input to workers and passed row indices, causing unnecessary memory usage and introducing an undefined
protein_indicesregression. Worker progress logging was also unreliable.The implementation now distributes pre-split per-protein data directly to workers, reducing the exported payload and improving multicore reliability.
Changes
inputandprotein_indices.protein_data.benchmark/profile_dataprocess_peak.Rfor stage-by-stage memory profiling.callr,ps, andprofmemdependencies toSuggests.Tests
dataProcess().LogIntensitiesVariance, when availableCoding guideline violations