Skip to content

feat(wasm): per-container and range deep reads with container ids - #1086

Open
zxch3n wants to merge 1 commit into
perf/wasm-kind-cachefrom
feat/wasm-container-bulk-read
Open

feat(wasm): per-container and range deep reads with container ids#1086
zxch3n wants to merge 1 commit into
perf/wasm-kind-cachefrom
feat/wasm-container-bulk-read

Conversation

@zxch3n

@zxch3n zxch3n commented Sep 3, 2026

Copy link
Copy Markdown
Member

Stack: 3/6 — merge order: #1093#1085#1086#1087#1090#1091

Summary

Stacked on #1085 (merge that first; GitHub will retarget this to main automatically).

1. cid format fix (potentially breaking)

LoroDoc.getDeepValueWithID() emitted the node cid as a Debug-style composite: idx:85, id:cid:92@2311024965712536503:Map (internal container index + id). It now emits the bare ContainerID string — cid:92@2311024965712536503:Map / cid:root-map:Map — exactly what the container's id property returns. No in-repo consumer parsed the old form (verified with rg); the pure-TS runtime in loro-js already emitted container.id, so this restores wasm/JS-runtime parity. The change is called out in the changeset.

2. Per-container getDeepValueWithID()

LoroMap / LoroList / LoroMovableList / LoroTree now expose getDeepValueWithID() returning the same { cid, value } node shape as the doc-level API; LoroText returns { cid, value: string }. One WASM call reads a whole subtree.

3. Range deep reads

LoroList.getRangeDeepValueWithID(start, end) / LoroMovableList.getRangeDeepValueWithID(start, end) return the deep-with-id nodes for items [start, end) in one call; getRangeValue(start, end) returns plain deep values without ids. Negative bounds clamp to 0, overflows clamp to the length, empty or inverted ranges return [].

Detached containers throw a readable error (MisuseDetachedContainer) instead of trapping — this required changing MovableListHandler::get_deep_value_with_id from an unwrap-on-detached to LoroResult (no other callers).

Tests

  • Rust: 4 new unit tests in loro-internal (cid == container.id for root/nested, text/tree node shapes, slice clamping/empty/inverted, detached errors). cargo test -p loro-internal and cargo test -p loro pass.
  • JS: new tests/deep_value.test.ts (11 tests). Full wasm suite: 27 files / 360 tests pass; tsc --noEmit clean.
  • TypeScript: typed via the repo's typescript_custom_section interfaces; new exported ValueWithContainerID type.

Wasm binary size

Dev build with debug info: 99,697,095 → 99,855,123 B (+158 KB, +0.16%).

- Fix getDeepValueWithID() cid field: emit the bare ContainerID string
  (the same as container.id) instead of the Debug-style
  'idx:N, id:cid:...' composite. Potentially breaking for consumers that
  parsed the old form; restores parity with the pure-TS runtime.
- Add getDeepValueWithID() on LoroMap/LoroList/LoroMovableList/LoroTree
  ({ cid, value } node) and LoroText ({ cid, value: string }).
- Add getRangeDeepValueWithID(start, end) and getRangeValue(start, end)
  on LoroList/LoroMovableList for one-call deep reads of a slice;
  bounds are clamped, empty or inverted ranges return [].
- Detached containers return a readable error instead of trapping.
  MovableListHandler::get_deep_value_with_id now returns LoroResult
  instead of unwrapping on detached handlers.

Wasm size (dev build, with debug info): +158 KB (+0.16%).
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