Skip to content

perf(sync): benchmark and optimize scoped first-view sync paths#104

Merged
Antonov548 merged 59 commits intomainfrom
sync/tree-sync-perf-benchmarks
Apr 3, 2026
Merged

perf(sync): benchmark and optimize scoped first-view sync paths#104
Antonov548 merged 59 commits intomainfrom
sync/tree-sync-perf-benchmarks

Conversation

@marcus-pousette
Copy link
Copy Markdown
Collaborator

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

What This Adds

  • product-shaped scoped sync benchmarks for opening a node on a fresh client: fetch the first page of a node's immediate children, with and without payloads
  • matching balanced subtree re-sync benchmarks for the case where a restarted client already has that scope locally and needs a normal non-empty scoped reconcile
  • a --first-view metric so sync time and first local read time are measured separately
  • sync-server fixture priming and reuse, so one-time upload/setup cost is measured separately from steady-state open cost
  • the protocol and Postgres sync-path changes needed to make these scoped paths fast enough to be meaningful

Benchmark Results

Reference first-view case: open a known node, fetch its first 10 immediate children, and include 512B payloads.

Fresh First View: Before vs After

  • before, on the old local Postgres 10k open path:
    • structure-only: about 18.06s total, with about 17.91s in server listOpRefs(children)
    • payload variant: about 26.77s total, with about 26.55s in server listOpRefs(children)
    • local SQLite apply and first local read were only a few milliseconds, so the bottleneck was the server-side scoped query path
  • after, in this PR:
    • local Postgres sync server, 10k tree: 27.5ms total time to first view, 27.1ms sync, 0.38ms first local read
    • local Postgres sync server, 100k tree: 27.6ms total time to first view, 27.2ms sync, 0.50ms first local read
    • remote sync server, 100k tree: 227.2ms total time to first view, 226.9ms sync, 0.79ms first local read

Same Subtree Re-Sync On A Non-Empty Client

  • local Postgres sync server, structure-only scoped re-sync:
    • 10k: 41.0ms sync-only
    • 100k: 59.2ms sync-only
  • local Postgres sync server, payload scoped re-sync:
    • 10k: 38.2ms sync-only
    • 100k: 56.5ms sync-only

What These Numbers Cover

  • the fresh first-view numbers are the empty-local-result case, where the protocol can sometimes skip a full RIBLT round and direct-send a tiny scoped result
  • the re-sync numbers are the non-empty case, so they measure the normal scoped reconcile path instead

Setup Cost Measured Separately

  • remote sync-server fixture prime for the same 100k first-view case is about 108.2s, and this PR measures that separately so upload/setup does not get mixed into the open-path numbers

Scope

This PR is about scoped first-view sync and subtree re-sync performance.

The later large-doc hot-write benchmark suite and its setup optimizations live in #113.

@marcus-pousette marcus-pousette force-pushed the sync/postgres-sync-backend-contract branch from 665a5da to cdedf03 Compare March 28, 2026 20:14
@marcus-pousette marcus-pousette force-pushed the sync/tree-sync-perf-benchmarks branch 4 times, most recently from 9e36164 to 4e30592 Compare March 30, 2026 06:20
@marcus-pousette marcus-pousette force-pushed the sync/tree-sync-perf-benchmarks branch from 4e30592 to 379d7e9 Compare March 30, 2026 09:21
@marcus-pousette marcus-pousette changed the title feat(benchmark): target real note tree sync paths perf(sync): benchmark and optimize scoped first-view sync paths Apr 1, 2026
@marcus-pousette marcus-pousette changed the base branch from sync/postgres-sync-backend-contract to main April 1, 2026 07:11
@marcus-pousette marcus-pousette marked this pull request as ready for review April 2, 2026 09:28
@Antonov548 Antonov548 merged commit 6f5fc0d into main Apr 3, 2026
2 checks passed
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