Skip to content

Analyze @tomic/lib vs atomic_lib duplication (and WASM tradeoffs) - #1278

Draft
joepio wants to merge 1 commit into
developfrom
cursor/ts-wasm-duplication-analysis-2b06
Draft

Analyze @tomic/lib vs atomic_lib duplication (and WASM tradeoffs)#1278
joepio wants to merge 1 commit into
developfrom
cursor/ts-wasm-duplication-analysis-2b06

Conversation

@joepio

@joepio joepio commented Aug 16, 2026

Copy link
Copy Markdown
Member

Related Issues

Analysis request: how much logic is duplicated between @tomic/lib and atomic_lib / WASM, and whether migrating the TS library onto WASM would help.

Summary

There are two different overlaps, and they should not be treated as one problem:

  1. Must-match protocol (~1.5–2.5k lines of TS): genesis certificates, commit canonical JSON, WS v2 frames, RBSR fingerprints, drive hashes, datatype tags. These must stay byte-identical with Rust. They are already pinned with golden vectors and run off the render path.
  2. Two embeddings of a Resource: TS Resource/Store is a React cache + outbox + TipTap LoroDoc. Rust Resource/Db is a durable node. Flutter already skipped the TS embedding and calls atomic_lib directly.

Recommendation: do not move Resource.get / the JS cache into WASM. Continue the existing AtomicNode / ClientDb direction for query, persist, and apply-commit.

Full write-up: planning/ts-wasm-duplication.md.

Measured costs (in-process; Worker would be slower)

Op Time
JS Resource.get(name) ~0.07 µs
WASM getResource → JSON-AD ~75 µs (~1000×)
WASM putResource (parse + index) ~575 µs
WASM blake3 1 KiB ~1.4 µs (faster than noble JS ~16 µs)
Native Ed25519 sign ~24 µs vs noble JS ~284 µs

WASM binaries already loaded by the browser: atomic_wasm 6.1 MB (2.3 MB gzip) + loro-crdt 3.1 MB (1.0 MB gzip). TipTap needs a main-thread loro-crdt LoroDoc; folding Resource into atomic_wasm does not remove that second heap.

How to reproduce

cargo run -p atomic_lib --example protocol_microbench --release
cd browser/lib && pnpm bench src/ts-vs-wasm.bench.ts   # needs wasm/pkg

Checklist

  • Add changelog entry linking to issue, describe API changes — N/A (planning + benches only)
  • Add or update tests if needed — added reproducible benches, not product tests
  • Update docs if needed — planning/ts-wasm-duplication.md + README index
Open in Web Open in Cursor 

Map what @tomic/lib reimplements from atomic_lib, add reproducible
benches, and recommend keeping the JS Resource cache while continuing
to push node work (query/persist/apply) into WASM.

Co-authored-by: joepmeindertsma <joepmeindertsma@gmail.com>
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.

2 participants