Skip to content

Improve scene serialization efficiency - #759

Merged
brentyi merged 2 commits into
mainfrom
serialization-efficiency
Aug 11, 2026
Merged

Improve scene serialization efficiency#759
brentyi merged 2 commits into
mainfrom
serialization-efficiency

Conversation

@brentyi

@brentyi brentyi commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator
  • StateSerializer.serialize() now deduplicates byte-identical binary buffers, shrinking recordings that re-send unchanged arrays (a 20-frame recording re-adding a 4MB mesh drops from 194MB to 9.7MB) while leaving duplicate-free scenes byte-identical.
  • Serialization streams message parts through a multithreaded zstd compressor instead of concatenating a full uncompressed copy first, removing a payload-sized memory spike.
  • The serializer unregisters before encoding so a concurrently queued message can no longer land a dangling buffer reference in the output.
  • Recording/embed decode logic moves from FilePlayback.tsx into a UI-free PlaybackDecode.ts, with embedded base64 decoded via native Uint8Array.fromBase64 when available and one less full copy of both downloaded and compressed payloads.
  • New tests cover the .viser format round-trip with an independent Python decoder (dedup invariants, dtype collisions, empty/non-contiguous arrays, concurrency, determinism) plus a vitest suite decoding a real Python-generated fixture end-to-end.

StateSerializer.serialize() now deduplicates byte-identical binary buffers
(remapping placeholder indices onto shared buffers), streams parts through
a multithreaded zstd compressor instead of concatenating a full uncompressed
copy first, and unregisters before encoding so concurrently queued messages
can't corrupt the output. A recording that re-adds a 4MB mesh over 20 frames
shrinks from 194MB to 9.7MB and serializes ~10x faster; recordings without
duplicate buffers are byte-identical to before.

Client: recording/embed decode logic moves from FilePlayback.tsx into a
UI-free PlaybackDecode.ts; embedded base64 decodes via native
Uint8Array.fromBase64 when available; downloads stream into a preallocated
buffer; the compressed payload is no longer copied before decompression.

Tests: Python round-trip suite for the .viser format with an independent
decoder (dedup invariants, dtype collisions, empty/non-contiguous arrays,
concurrency, determinism, as_html payload), and a vitest suite decoding a
real Python-generated fixture end-to-end.
The starred list display evaluated flush() before consuming the compress()
generator on 3.8 (BUILD_LIST_UNPACK evaluates operands before concatenating),
raising 'cannot call compress() after compressor finished'.
@brentyi
brentyi merged commit 46b31a9 into main Aug 11, 2026
23 checks passed
@brentyi
brentyi deleted the serialization-efficiency branch August 11, 2026 08:12
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