perf: reduce SQL round-trips in scheduler hot paths#57
Merged
Conversation
The iterative BFS issued one SQL round-trip per graph node, producing O(n²) total queries for linear dependency chains (~19,900 for depth 200). A single recursive CTE collapses each cycle check to one query, yielding an 82% speedup at depth 200.
Combine completion + dependency resolution into a single transaction, cache next_run_after to skip the query when no scheduled tasks exist, carry tags from peek to pop to avoid a redundant populate_tags query, skip tag queries entirely when the store has never had tags inserted, and skip the paused_tasks query when no tasks have been preempted. Benchmarked at ~40% improvement on dep_chain_dispatch/50 (42ms → 26ms) and ~20-34% on fan-in dispatch benchmarks.
…-trips - Batch resolve_dependency_edges: replace 3N per-dep queries (history check, active check, edge insert) with 3 batch queries using IN clauses - Single-pass cycle detection: seed one recursive CTE with all dep IDs instead of running N separate CTEs - Replace pop_by_id_no_tags (UPDATE RETURNING *) with claim_task (UPDATE only), reusing the TaskRecord already fetched by peek_next Benchmarked improvement on dep_fan_in_dispatch: width=10: -15% (5.2ms → 4.4ms) width=50: -19% (21.7ms → 17.5ms) width=100: -14% (40.5ms → 34.8ms)
…mpatibility Move pprof to an optional dependency gated by a `profile` feature so benchmarks can run in CI without requiring perf_event_open. Local profiling is still available via `cargo bench --features profile`. Also simplify TTL expiry check in run_loop to use if-let instead of unwrap.
Merged
Contributor
Benchmark ComparisonClick to expand |
deepjoy
pushed a commit
that referenced
this pull request
Mar 19, 2026
## 🤖 New release * `taskmill`: 0.5.1 -> 0.5.2 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.5.2](v0.5.1...v0.5.2) - 2026-03-19 ### Other - reduce SQL round-trips and CPU overhead in scheduler hot paths ([#60](#60)) - coalesce task completions into batched transactions ([#59](#59)) - reduce SQL round-trips in scheduler hot paths ([#57](#57)) </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
complete_with_record_and_resolvecombines thecomplete_with_recordandresolve_dependentscalls, eliminating aBEGIN IMMEDIATE/COMMITcycle on every task completion.has_paused_tasks(atomic bool) skips thepaused_tasks()query when nothing has been preempted;has_tagsskipspopulate_tagswhen no tags exist;check_scheduledskipsnext_run_afterwhen no scheduled tasks are present.claim_taskuses a simpleUPDATE … SET status='running'withoutRETURNING *, patching the already-held in-memoryTaskRecordinstead of re-fetching the full row.profilefeature: Movespproffrom a mandatory dev-dependency to an optional feature, fixing CI builds on platforms where pprof fails to compile.Module→Domain<D>API transition.