Skip to content

perf(lib): speed up commits via Loro fork + incremental sign - #1250

Draft
joepio wants to merge 5 commits into
developfrom
cursor/commit-performance-a52a
Draft

perf(lib): speed up commits via Loro fork + incremental sign#1250
joepio wants to merge 5 commits into
developfrom
cursor/commit-performance-a52a

Conversation

@joepio

@joepio joepio commented Aug 3, 2026

Copy link
Copy Markdown
Member

Summary

Speeds up the commit hot path and Db::init_temp (the setup tax every test/bench pays).

Bottlenecks

Commit path

  1. Resource::clone / build_state_doc did export_snapshot() + from_snapshot() (paid multiple times per commit)
  2. apply_changes double-cloned resource_old
  3. sign_at always exported a full snapshot as loroUpdate despite its docstring

Db::init_temp (related only as shared test overhead)

  1. Cold path re-runs ontology bootstrap every call (~120 ms release; ~1.75 s debug)
  2. RedbStore::new_file used redb’s 1 GiB default cache despite comments saying Builder would drop it

Fixes

  • AtomicLoroDoc::fork() for in-process clones / working docs
  • One pre-edit resource copy on apply (not two)
  • sign_at exports export_updates_since(persisted_vv) for follow-ups (genesis still full snapshot)
  • init_temp copies a process-local bootstrapped atomic.redb template after the first call
  • redb file opens use a 64 MiB cache (16 MiB for temp DBs)

Before / after (release, same machine; before = develop @ 7863501)

Metric Before After
Db::init_temp (warm / Nth call in a process) ~120 ms ~10 ms
edit_save_locally (10 prior edits) ~2.1 ms ~1.7 ms
Follow-up loroUpdate size (20-edit history) ~6585 B (≈ full snapshot) 157 B
Resource::clone (50-edit doc) ~195 µs/op ~197 µs/op

Clone wall-clock is flat at this doc size (Loro fork is also O(n)); the clear wins are incremental payloads, fewer apply clones, and init_temp.

cargo bench -p atomic_lib --bench commit_bench --features db-redb
cargo test -p atomic_lib --features db-redb --lib -- commit:: resources::

See planning/commit-performance.md.

Related Issues

N/A — performance investigation.

Checklist

  • Add changelog entry
  • Add or update tests if needed
  • Update docs if needed (planning/commit-performance.md)
Open in Web Open in Cursor 

@joepio
joepio force-pushed the cursor/commit-performance-a52a branch from b00aec1 to 6b8bffb Compare August 3, 2026 09:10
@cursor
cursor Bot force-pushed the cursor/commit-performance-a52a branch from 6b8bffb to d527c9b Compare August 3, 2026 09:55
@joepio
joepio force-pushed the cursor/commit-performance-a52a branch from d527c9b to 52cf542 Compare August 4, 2026 08:02
cursoragent and others added 5 commits August 5, 2026 09:56
Resource::clone and build_state_doc no longer serialize/deserialize a full
Loro snapshot; they fork in-memory. apply_changes drops its internal
resource_old clone (caller keeps one copy). sign_at exports
export_updates_since(persisted_vv) for follow-up edits instead of a full
snapshot, cutting per-commit payload and history growth.

Adds commit_bench and a regression test that follow-up loroUpdates stay
incremental. See planning/commit-performance.md.

Co-authored-by: Joep Meindertsma <joep@ontola.io>
Co-authored-by: Joep Meindertsma <joep@ontola.io>
…ache

Bootstrap dominates cold init_temp (~120ms release). Cache a process-local
bootstrapped atomic.redb and fs::copy it for each subsequent call (~10ms).
Also route file opens through redb Builder with a 64 MiB cache (16 MiB for
temp DBs) instead of the unused 1 GiB default the comments already intended.

Co-authored-by: Joep Meindertsma <joep@ontola.io>
Co-authored-by: Joep Meindertsma <joep@ontola.io>
The new helper was missing the not(wasm32) cfg that new_file_with_cache
already has, so wasm-pack failed with E0599 in CI.

Co-authored-by: Joep Meindertsma <joep@ontola.io>
@joepio
joepio force-pushed the cursor/commit-performance-a52a branch from 52cf542 to 6e5cae7 Compare August 5, 2026 07:56
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