-
Notifications
You must be signed in to change notification settings - Fork 144
Fix slow onInsert awaitMatch performance issue #1029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The buffer was being cleared at the start of each new batch, which caused messages to be lost when multiple batches arrived before awaitMatch was called. This led to: - awaitMatch timing out (~3-5s per attempt) - Transaction rollbacks when the timeout threw an error The fix removes the buffer clearing between batches. Messages are now preserved until the buffer reaches MAX_BATCH_MESSAGES (1000), at which point the oldest messages are dropped. This ensures awaitMatch can find messages even when heartbeat batches or other sync activity arrives before the API call completes. Added test case for the specific race condition: multiple batches (including heartbeats) arriving while onInsert's API call is in progress.
|
More templates
@tanstack/angular-db
@tanstack/db
@tanstack/db-ivm
@tanstack/electric-db-collection
@tanstack/offline-transactions
@tanstack/powersync-db-collection
@tanstack/query-db-collection
@tanstack/react-db
@tanstack/rxdb-db-collection
@tanstack/solid-db
@tanstack/svelte-db
@tanstack/trailbase-db-collection
@tanstack/vue-db
commit: |
|
Size Change: 0 B Total Size: 88.5 kB ℹ️ View Unchanged
|
|
Size Change: 0 B Total Size: 3.35 kB ℹ️ View Unchanged
|
Update todo examples to use ^1.0.8 to match other examples and fix sherif version consistency check.
26d78ae to
00f9f60
Compare
samwillis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is OK, and fixes the immediate problem, but I suspect there is still an edge case where if there are more than 1k updates in the batch before the awaitMatch call, but after the actual change synced then it could be missed.
Maybe we merge this, but file an issue to come back and reassess the design of awaitMatch.
The buffer was being cleared at the start of each new batch, which caused messages to be lost when multiple batches arrived before awaitMatch was called. This led to:
The fix removes the buffer clearing between batches. Messages are now preserved until the buffer reaches MAX_BATCH_MESSAGES (1000), at which point the oldest messages are dropped. This ensures awaitMatch can find messages even when heartbeat batches or other sync activity arrives before the API call completes.
Added test case for the specific race condition: multiple batches (including heartbeats) arriving while onInsert's API call is in progress.
🎯 Changes
✅ Checklist
pnpm test:pr.🚀 Release Impact