Repository navigation
Reduce memory use and processing time for similarity preparation - #38
Draft
weitse-hsu wants to merge 14 commits into
Draft
weitse-hsu wants to merge 14 commits into
weitse-hsu wants to merge 14 commits into
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.
Hi, I ran into high memory use and a suspected out-of-memory failure during similarity preparation when using S2 with Foldseek on a larger dataset. This PR reduces memory use and speeds up preparation while preserving the numerical results for identical inputs.
This builds on the fixes proposed in #36. I’ve kept the performance work in a separate PR to make it easier to review. If both are accepted, merging #36 first would keep the changes separate. I can update this branch once those fixes are in main and mark this draft ready for review.
Changes
--foldseek-sort-memoryto configure the sorting buffer, defaulting to256M(9a2ade5).Foldseek alignment processing now requires GNU sort and trades additional temporary disk space for lower RAM use.
Performance comparison
I compared the version containing the fixes proposed in #36 (65ce26a) with the version containing those fixes plus the performance changes in this PR (9a2ade5). Both processed the same 2048 interaction records and 10.35 million saved Foldseek alignment rows. Each version was run in three replicates.
Times below are medians. Memory is the median sampled process-tree peak RSS, including the external sorter.
Commit links identify the relevant changes, not separately measured contributions from each commit. Later commits on this branch only updated tests and fixture names.
Overall, the combined preparation took 461.68–469.66 s for the baseline and 53.29–55.22 s for the candidate. The reduced memory use comes with more temporary disk use, increasing from 1.01 to 2.41 GiB.
These measurements exclude native Foldseek search/export and final optimization, so they do not represent an end-to-end split speedup. Loading and aggregation were measured separately in fresh processes and should not be added to the preparation time.
Validation
All repetitions passed exact comparisons of the relevant matrix bytes, ordered identifiers and mappings, cluster memberships and weights. The complete preparations also produced identical canonical optimization-model data, without numerical tolerances.
Regression tests cover external-sort spilling, numeric edge cases, identifier handling, matrix loading, aggregation and matrix-copy behavior. The existing chain-selection rules are preserved, including their handling of tied hits.
I’ve attached a script that generates a small synthetic example with 64 entities and checks that the two versions produce identical similarity matrices and optimization-model data. (See compare_scalability.py and
README.md.) It does not require the benchmark dataset or run Foldseek searches or split optimization. Its timings are illustrative and do not reproduce the workload measured above.
I’d be happy to adjust the implementation based on your feedback. Thanks for taking a look!