Benchmarks

The benchmark suite measures overhead added by svelte-realtime on top of raw WebSocket messaging.

Run with:

node bench/rpc.js

What gets measured

  • RPC dispatch overhead: time for handleRpc to parse, look up the registry, build ctx, execute, and respond - compared to calling the function directly
  • Stream merge throughput: operations per second for each merge strategy (crud, latest, set, presence, cursor) applying events to arrays of varying sizes
  • Fast-path rejection: how quickly non-RPC messages are identified and skipped

Merge strategy internals

Merge strategies use an internal Map<key, index> for O(1) lookups instead of linear scans. Updates and upserts on keyed strategies (crud, presence, cursor) are constant-time regardless of array size. Deletes and prepends require an index rebuild (linear), which matches the cost of the delete itself.

Event batching (browser)

In the browser, incoming pub/sub events are queued and flushed once per requestAnimationFrame instead of triggering a Svelte store update per event. This is automatic - no configuration needed.

With high-frequency streams (e.g. 1000 cursors at 20 updates/sec), this reduces reactive store updates from ~20,000/sec to ~60/sec (one per frame). All merge operations still run, but Svelte only diffs and re-renders once per frame.

In Node/SSR (tests, __directCall, etc.), events apply synchronously - no batching overhead.

Methodology

These benchmarks run in-process with mock objects (no real network). They isolate the framework overhead from network latency. See bench/rpc.js for the full source.

Running tests

npm test

Was this page helpful?