Skip to content

perf: benchmark and optimize large-doc write and sync paths#113

Draft
marcus-pousette wants to merge 19 commits intomainfrom
sync/hot-write-benchmarks
Draft

perf: benchmark and optimize large-doc write and sync paths#113
marcus-pousette wants to merge 19 commits intomainfrom
sync/hot-write-benchmarks

Conversation

@marcus-pousette
Copy link
Copy Markdown
Collaborator

@marcus-pousette marcus-pousette commented Mar 30, 2026

This PR improves large-doc write and sync performance and adds benchmark coverage to measure those paths repeatably. The main runtime work is in the Postgres backend, with supporting benchmark instrumentation in the playground and benchmark runners.

Runtime changes

  • add a Postgres-side cached replica counter path for local-op creation
    • treecrdt_replica_meta stores per-replica max counters
  • add a seeded core construction path used by the Postgres local-op flow

Benchmark and test support

  • add hot-write benchmarks for large existing docs: payload edits, sibling inserts, and move cases
  • add reusable large-doc fixture setup for Postgres-backed runs
  • keep @treecrdt/postgres-napi runtime-only and move fixture helpers under @treecrdt/postgres-napi/testing
  • add playground live-write instrumentation for measuring remote writes on preseeded docs
  • make read-only sync benches reuse matching seeded trees across reruns by default
  • allow dedicated environments to prime remote fixtures directly with --postgres-url

Representative results

  • remote partial-tree first-view on eu.sync.emhub.net
    • 10k structure-only: 266ms
    • 10k payload subtree: 242ms
    • 100k payload subtree: 210ms to 227ms
  • public regional live-write
    • eu.sync.emhub.net: 189.9ms
    • us.sync.emhub.net: 241.3ms
    • sync.emhub.net: 254.8ms
  • hot writes on existing 1m trees
    • Postgres N-API: payload edit 1.8ms, insert sibling 3.5ms, move leaf 47.7ms
    • sqlite-node file: payload edit 0.82ms, insert sibling 1.23ms, move leaf 2.20ms
    • sqlite-node memory: payload edit 0.13ms, insert sibling 0.23ms, move leaf 0.81ms

Not in scope here: public-host 1m seeding and remote re-sync results.

@marcus-pousette marcus-pousette changed the title bench: add warm hot-write benchmark mode bench: benchmark and optimize large-doc write and sync paths Mar 31, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 1, 2026

Benchmarks

Triggered by workflow_dispatch (default) - Run: https://github.com/cybersemics/treecrdt/actions/runs/23849500797
Suite: high-value default (default)
Base: sync/doc-discovery-contract (69c02a2) - Head: sync/hot-write-benchmarks (c5c752e)
Compared entries: 8 - Improved: 2 - Regressed: 0

Impl Storage Workload Base ops/s Head ops/s Δ ops/s Base p50 ms Head p50 ms Δ p50 Status
postgres-napi postgres hot-write-insert-sibling-fanout10-100000-warm2-repeat10 - 9.22 - - 108.49 -
postgres-napi postgres hot-write-payload-edit-fanout10-100000-warm2-repeat10 - 18.30 - - 54.64 -
sqlite-node file hot-write-insert-sibling-fanout10-100000-warm2-repeat10 - 502.51 - - 1.99 -
sqlite-node file hot-write-payload-edit-fanout10-100000-warm2-repeat10 - 584.41 - - 1.71 -
sqlite-node file sync-balanced-children-payloads-cold-start-fanout10-100000-first-view 24.93 566.36 +2171.84% 842.37 37.08 -95.60% 🔴
sqlite-node memory hot-write-insert-sibling-fanout10-100000-warm2-repeat10 - 2175.54 - - 0.46 -
sqlite-node memory hot-write-payload-edit-fanout10-100000-warm2-repeat10 - 2428.30 - - 0.41 -
sqlite-node memory sync-balanced-children-payloads-cold-start-fanout10-100000-first-view 377.82 451.79 +19.58% 55.58 46.48 -16.37% 🟠

Status: ✅ <5% change | 🟡 5–10% | 🟠 10–30% | 🔴 >30%

Artifacts:

  • base summary: bench-base/benchmarks/summary.json
  • head summary: bench-head/benchmarks/summary.json

@marcus-pousette
Copy link
Copy Markdown
Collaborator Author

/bench

@marcus-pousette marcus-pousette changed the title bench: benchmark and optimize large-doc write and sync paths perf: benchmark and optimize large-doc write and sync paths Apr 2, 2026
@marcus-pousette marcus-pousette force-pushed the sync/hot-write-benchmarks branch from 2e7e8e2 to e9842be Compare April 4, 2026 10:40
@marcus-pousette marcus-pousette force-pushed the sync/doc-discovery-contract branch from 5d14cae to 178c469 Compare April 4, 2026 10:40
@marcus-pousette marcus-pousette force-pushed the sync/hot-write-benchmarks branch from 95df399 to 7d7c893 Compare April 6, 2026 20:51
@marcus-pousette marcus-pousette changed the base branch from sync/doc-discovery-contract to main April 8, 2026 11:08
@marcus-pousette marcus-pousette force-pushed the sync/hot-write-benchmarks branch from c983b86 to f890a7a Compare April 9, 2026 15:44
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