Skip to content

Reduce overhead in the typescript sdk#4744

Merged
joshua-spacetime merged 1 commit intomasterfrom
joshua/ts-sdk-perf
Apr 6, 2026
Merged

Reduce overhead in the typescript sdk#4744
joshua-spacetime merged 1 commit intomasterfrom
joshua/ts-sdk-perf

Conversation

@joshua-spacetime
Copy link
Copy Markdown
Collaborator

@joshua-spacetime joshua-spacetime commented Apr 3, 2026

Description of Changes

1. Cache the connection-id hex prefix and reuse it when generating event IDs

Previously, the SDK rebuilt the connection-id string on every event. Now it computes the prefix once per connection-id update and reuses it.

2. Replace Promise-chained inbound message processing with a synchronous ordered drain loop

Now inbound messages are still processed through a direct drain loop instead of a promise chain to reduce scheduler overhead.

3. Cache encoded reducer/procedure names and use specialized CallReducer/CallProcedure writers

Previously, reducer/procedure calls always went through the generic ClientMessage object path and re-encoded the method name each time. Now the SDK caches UTF-8 encoded reducer/procedure names and uses direct CallReducer / CallProcedure writers on the hot path, while keeping the generic path as fallback.

API and ABI breaking changes

None

Expected complexity level and risk

2

Testing

Manual: 100K -> 130K TPS running keynote-2 benchmark on apple m2

MAX_INFLIGHT_PER_WORKER=512 pnpm run bench test-1 --seconds 10 --concurrency 50 --alpha 1.5 --connectors spacetimedb

@joshua-spacetime joshua-spacetime changed the title Reducer overhead in the typescript sdk Reduce overhead in the typescript sdk Apr 3, 2026
Copy link
Copy Markdown
Collaborator

@coolreader18 coolreader18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@joshua-spacetime joshua-spacetime added this pull request to the merge queue Apr 6, 2026
Merged via the queue into master with commit 2a8718b Apr 6, 2026
36 of 37 checks passed
@joshua-spacetime joshua-spacetime deleted the joshua/ts-sdk-perf branch April 6, 2026 20:42
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