Repository navigation
Use query workers by default, but only for large fan-outs - #63
Merged
Merged
Conversation
Query workers were off unless ONEBASE_QUERY_WORKERS was set. Turning them on for every background re-run would have made small apps worse: with 10 subscribers an update took 1.5-2 ms where it took 0.5 ms, a worker cost 15-30 MB, and the first update after a start or deploy waited 25-58 ms for the worker to load the code. So a round of background re-runs now starts on the main thread, and only what is left after 4 ms goes to the workers. The first worker starts the first time a round runs that long, and the main thread carries on until it is ready. A small fan-out is handled exactly as with workers off and starts no worker; with 2,000 subscribers the main thread is busy 26 ms per write, where it was 100 ms. The default is 2 workers, 1 on two cores, none on one. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
Query workers (SQLite) were off unless
ONEBASE_QUERY_WORKERSwas set. They are now on by default, and used only when a write affects enough live queries to keep the main thread busy.QUERY_WORKERS_AFTER_MS), the rest goes to the workers. The first worker starts the first time that happens, and the main thread carries on until the worker has loaded the code.ONEBASE_QUERY_WORKERS=0keeps every query on the main thread, as before.queryWorkersAfterMsis a newRuntimeoption;0sends every background re-run to a worker, which is the old behaviour of an explicit setting. The existing worker tests use it.Why not simply flip the default
Measured with
scripts/bench-query-workers.tson a 20-core machine, sending every background re-run to a worker:The first update after a start or deploy also took 25–58 ms instead of 1–2 ms, while the worker loaded the code.
With this change, at 10 subscribers the numbers match workers off and no worker is started. At 2,000 subscribers (heavier query) the main thread is busy 26 ms per write and everyone is updated in 48 ms, against 100 ms and 86 ms with workers off.
For the reviewer
ONEBASE_QUERY_WORKERS: small fan-outs now stay on the main thread for them too. That is faster for those writes, but it is a change.Testing
bun teston SQLite: 580 pass, 3 skipped, 0 fail. Postgres, MySQL and libSQL never use query workers; CI runs them.onebase_query_worker_runs_totalwas 546, and the log had no warnings.docs/functions.mdhas the re-measured table;SUBSCRIBERS=10 bun scripts/bench-query-workers.tsreproduces the small case.🤖 Generated with Claude Code