perf: batch dispatch and completion SQL to reduce round-trips (~56% faster)#61
Merged
Conversation
…aster) - Add `pop_next_batch(limit)` to claim up to N pending tasks in a single UPDATE...RETURNING...LIMIT statement, replacing the one-at-a-time `pop_next()` loop in the scheduler dispatch path - Add `dispatch_pending()` which fills all concurrency slots in one SQL round-trip on the fast path (no gate checks) - Skip tag-related SQL (history-tag copy INSERT, delete_task_tags DELETE) when the store's `has_tags` flag is false, avoiding 2 no-op round-trips per task completion - Restructure `complete_batch_with_resolve` for non-recurring batches to use single batched DELETE/UPDATE statements instead of per-task loops, reducing SQL from ~5N to N+4 per batch Benchmarks (dispatch_and_complete_1000): ~450ms → ~200ms (-56%) Concurrency scaling/8: ~274ms → ~88ms (-68%) Mixed priority dispatch: ~241ms → ~93ms (-60%)
Merged
deepjoy
pushed a commit
that referenced
this pull request
Mar 19, 2026
## 🤖 New release * `taskmill`: 0.5.2 -> 0.5.3 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.5.3](v0.5.2...v0.5.3) - 2026-03-19 ### Other - batch dispatch and completion SQL to reduce round-trips (~56% faster) ([#61](#61)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.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.
Summary
pop_next_batch(limit)toTaskStorethat claims up to N pending tasks in a singleUPDATE…RETURNING…LIMITstatement, replacing the sequential one-at-a-timepop_next()loop when filling concurrency slotsdispatch_pending()fast path in the scheduler run loop that fills all available concurrency slots in one SQL round-trip (falls back to per-task gate-checked dispatch on the slow path)skip_tagsflag throughinsert_history()andcomplete_inner()so that when the store'shas_tagsflag isfalse, the no-op history-tag copy INSERT anddelete_task_tagsDELETE are skipped entirely (2 SQL round-trips saved per task completion)complete_batch_with_resolvefor non-recurring batches to use single batchedDELETE FROM tasks WHERE id IN (…),DELETE FROM task_tags, andDELETE FROM task_depsstatements instead of per-task loops, reducing SQL from ~5N to N+4 per batchBenchmark results
dispatch_and_complete_1000concurrency_scaling/1concurrency_scaling/2concurrency_scaling/4concurrency_scaling/8mixed_priority_dispatch_500submit_1000_tasksbatch_submit_1000