Fix unnecessary deepcopy in validate_psm_list causing OOM on large PSM lists#24
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
validate_psm_list()unconditionally calledcopy.deepcopy()on the filteredPSMListon every call topredict(),calibrate(), andpredict_and_calibrate(). This was flagged by a# TODO: Is deepcopy really necessary or can it be avoided?comment at the time it was introduced (d7a016a), but never resolved.This surfaced as an OOM crash when running IM2Deep through MS²Rescore on a large timsTOF immunopeptidomics dataset (PSM list expanded by Mumble's mass-shift candidate search). The process was killed by
earlyoomat ~78 GB RSS after several minutes of steadily ramping memory, while the equivalent DeepLC step on the same PSM list completed quickly.Investigation
Roughly linear, ~4.7 KB/PSM. On a Mumble-exploded PSM list in the millions, this alone accounts for tens of GB and the multi-minute "slow ramp" observed before the kill.
deeplc._parse_psms(DeepLC's equivalent entry point) does no copying at all when given aPSMList— this was the actual asymmetry, not the shared feature-encoding path.Fix
The
deepcopyis only structurally necessary because theneeds_target=Truebranch mutates PSMs in place (psm.metadata["CCS"] = ...), and boolean-maskPSMListindexing sharesPSMinstances with the input rather than cloning them (verified directly). For the plainpredict()path (needs_target=False, what MS²Rescore's feature generator uses), nothing downstream mutates any PSM, so the copy was pure overhead.Made the
deepcopyconditional onneeds_target, matching what it actually protects against.Caveat for reviewers
predict_and_calibrate()callsvalidate_psm_list(psm_list)with the defaultneeds_target=Falsefor its primarypsm_listargument, then later does:Previously this ran against an isolated deep copy, so the mutation never reached the caller's original object. With this fix,
predict_and_calibrate()will now mutate the caller-suppliedpsm_listin place (attachpredicted_CCS_uncalibratedto metadata). This has no impact on MS²Rescore (it only callspredict(), neverpredict_and_calibrate()), but it is a visible behavior change for any other direct consumer of this function. Flagging so you can decide whether that's acceptable or whetherpredict_and_calibrate()needs its own explicit copy ofpsm_listrestored.