Skip to content

perf: batch dispatch and completion SQL to reduce round-trips (~56% faster)#61

Merged
deepjoy merged 1 commit into
mainfrom
perf-dispatch-complete
Mar 19, 2026
Merged

perf: batch dispatch and completion SQL to reduce round-trips (~56% faster)#61
deepjoy merged 1 commit into
mainfrom
perf-dispatch-complete

Conversation

@deepjoy
Copy link
Copy Markdown
Owner

@deepjoy deepjoy commented Mar 19, 2026

Summary

  • Add pop_next_batch(limit) to TaskStore that claims up to N pending tasks in a single UPDATE…RETURNING…LIMIT statement, replacing the sequential one-at-a-time pop_next() loop when filling concurrency slots
  • Add dispatch_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)
  • Thread a skip_tags flag through insert_history() and complete_inner() so that when the store's has_tags flag is false, the no-op history-tag copy INSERT and delete_task_tags DELETE are skipped entirely (2 SQL round-trips saved per task completion)
  • Restructure complete_batch_with_resolve for non-recurring batches to use single batched DELETE FROM tasks WHERE id IN (…), DELETE FROM task_tags, and DELETE FROM task_deps statements instead of per-task loops, reducing SQL from ~5N to N+4 per batch

Benchmark results

Benchmark Before After Change
dispatch_and_complete_1000 ~450 ms ~200 ms -56%
concurrency_scaling/1 ~310 ms ~146 ms -50%
concurrency_scaling/2 ~227 ms ~113 ms -51%
concurrency_scaling/4 ~240 ms ~95 ms -59%
concurrency_scaling/8 ~274 ms ~88 ms -68%
mixed_priority_dispatch_500 ~241 ms ~93 ms -60%
submit_1000_tasks ~60 ms ~60 ms no change
batch_submit_1000 ~13 ms ~13 ms no change

…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%)
@deepjoy deepjoy enabled auto-merge (squash) March 19, 2026 08:08
@deepjoy deepjoy merged commit 659c2d5 into main Mar 19, 2026
1 of 2 checks passed
@github-actions github-actions Bot mentioned this pull request Mar 19, 2026
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>
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.

1 participant