perf(wasm): cache container kind() on JS wrappers - #1085
Open
zxch3n wants to merge 1 commit into
Open
Conversation
Contributor
WASM Size Report
|
kind() returns a constant string per container class but the wasm-bindgen glue crossed into WASM and allocated a fresh JS string on every call. Memoize it once per class next to the existing per-wrapper id cache. Measured with scripts/measure-container-id.cjs (1M repeated reads): 164.5 ms -> 1.0 ms, wasm string decodes 1,000,000 -> 0.
zxch3n
force-pushed
the
perf/wasm-kind-cache
branch
from
September 4, 2026 04:15
8fe17a8 to
41af25e
Compare
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.
Stack: 2/6 — merge order: #1093 → #1085 → #1086 → #1087 → #1090 → #1091
Summary
kind()on container wrappers (LoroMap/LoroList/LoroText/LoroTree/LoroMovableList/LoroCounter) returns a constant string per class, but every call crossed into WASM and allocated a fresh JS string viagetStringFromWasm0. On a real document with ~70k containers, loro-mirror-style traversal calledkind()230k times per full read (andid333k times; theidcache already landed in #1073).This extends the existing
container_id_cache_patch.jsmechanism with a class-level memo forkind(). Reads afterfree()still raise wasm-bindgen's null-pointer error (the memo is bypassed for a zero__wbg_ptr), and Rust-sidekind()reads injs_to_containershare the same memo.Measured (scripts/measure-container-id.cjs, 1M repeated reads of one wrapper)
Tests
tests/container_id_cache.test.ts: repeatedkind()calls return the same string with zero additional wasm string decodes; at most one decode per container class; post-free()reads still throw.tsc --noEmitclean.Wasm binary size
No change — this is a pure JS-glue patch.
Part 1 of the bulk-read series; the follow-up (per-container/range deep reads) stacks on this branch.