Skip to content

perf: reduce snapshot read memory retention#985

Merged
zxch3n merged 70 commits into
mainfrom
feat/optimize-snapshot-read-memory
May 25, 2026
Merged

perf: reduce snapshot read memory retention#985
zxch3n merged 70 commits into
mainfrom
feat/optimize-snapshot-read-memory

Conversation

@lodyai
Copy link
Copy Markdown
Contributor

@lodyai lodyai Bot commented May 22, 2026

Summary

  • Avoid retaining decoded snapshot values/states for lazy containers during read-only traversal.
  • Route Map/List/MovableList handler reads through no-retain read helpers used by toJSON and loro-mirror style reads.
  • Keep root discovery lazy and avoid repeated root KV scans.
  • Include compact internal representation work for container store, list/map state, and richtext snapshot loading.

Measurements

Using the 32 MB fixture probe after exporting/importing a snapshot:

  • toJSON() then dropping JSON: 41.81 MB -> 25.58 MB
  • mirror shallow read: 41.81 MB -> 25.58 MB
  • mirror schema root read: 43.79 MB -> 25.58 MB
  • after a few inserts on the snapshot doc: 30.34 MB

Tradeoff: repeated full read-only traversals decode again instead of reusing retained decoded values. Current release probe timings were roughly toJSON 72 ms, mirror shallow 79/59 ms, and mirror schema root 143/131 ms.

Validation

  • cargo check -p loro-internal
  • cargo test -p loro-internal handler --lib
  • cargo test -p loro-internal map --lib
  • cargo test -p loro-internal list --lib
  • cargo test -p loro-internal snapshot --lib
  • cargo test -p loro-internal richtext --lib
  • git diff --check

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 22, 2026

WASM Size Report

  • Original size: 2999.99 KB
  • Gzipped size: 990.48 KB
  • Brotli size: 695.90 KB

@lodyai lodyai Bot force-pushed the feat/optimize-snapshot-read-memory branch from 65d6c6e to 6f0cbaa Compare May 22, 2026 16:50
@zxch3n zxch3n merged commit 8f57f4c into main May 25, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant