fix: reduce loro-js snapshot memory - #1051
Merged
Merged
Conversation
zxch3n
marked this pull request as ready for review
July 21, 2026 02:39
Contributor
WASM Size Report
|
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.
Summary
Why
Importing the 11.4 MB test document eagerly decoded 115,147 containers and materialized the full 423,797-operation history. A local edit then duplicated more history/state structures, and snapshot export allocated another set of encoded buffers. This amplified the document to roughly 703 MiB heap after import, over 860 MiB after one edit, and about 1.66 GiB peak RSS during snapshot export.
The new representation keeps the immutable snapshot bytes as the base, materializes only accessed or dirty state, and appends new history to an overlay until an API genuinely needs arbitrary historical traversal.
Impact
On the supplied 11,387,982-byte test document:
The ordinary fully materialized snapshot path did not regress. After three warmups, two 15-sample B4 A/B runs measured 110.5/107.0 ms medians at the parent revision and 107.7/107.7 ms on this branch. Both emitted identical 309,780-byte snapshots.
Validation
pnpm --dir loro-js checkgit diff --check