refactor(taskmill): split large modules into focused submodules and optimize completion hot path#25
Merged
Conversation
…submodules Break the two largest files — store.rs (2,287 lines) and scheduler/mod.rs (1,950 lines) — into focused submodules for better navigation and comprehension. scheduler/mod.rs splits into: - scheduler/builder.rs (SchedulerBuilder) - scheduler/event.rs (SchedulerEvent, SchedulerSnapshot, ShutdownMode, SchedulerConfig) store.rs splits into a store/ directory: - store/mod.rs (TaskStore struct, open/migrate/recover, config, pruning) - store/submit.rs (submit, submit_batch + DRY submit_one helper) - store/lifecycle.rs (pop/complete/fail/pause/resume + DRY insert_history helper) - store/query.rs (all read-only queries) - store/hierarchy.rs (parent-child hierarchy operations) - store/row_mapping.rs (shared row-to-struct mapping) DRY fixes: extract insert_history() (eliminates duplicated 22-column INSERT between complete/fail) and submit_one() (eliminates duplicated 3-step dedup logic between submit/submit_batch). No public API changes.
Three optimizations to reduce SQL round-trips per task lifecycle: 1. peek_next uses subquery so the partial index on (status, priority, id) acts as a covering index — the outer SELECT fetches only the winning row by primary key instead of scanning all pending rows. 2. Add complete_with_record / fail_with_record that accept the in-memory TaskRecord, skipping the redundant SELECT * that re-read a row the caller already held. Dispatch and parent-resolution paths now use these variants. The requeue flag (which may be set by a concurrent submit) is handled via conditional DELETE/UPDATE instead of a SELECT-then-branch. 3. Replace compute_duration_ms SQL (julianday round-trip) with pure Rust chrono arithmetic — one fewer statement per transaction. Net effect: complete() goes from 5 SQL statements to 3, reducing write-lock hold time. Benchmarks show 9-16% improvement on concurrency_scaling and 7% on mixed_priority_dispatch.
…into focused submodules Break down the three largest files by separation of concerns: - scheduler/mod.rs (1440→199 lines): extract submit.rs, run_loop.rs, control.rs, queries.rs, and tests.rs - registry.rs (537 lines): convert to registry/ directory with context.rs, state.rs, child_spawner.rs, and io_tracker.rs - task.rs (751 lines): convert to task/ directory with submission.rs, typed.rs, error.rs, dedup.rs, and tests.rs Also deduplicate SpawnContext construction via build_spawn_context() helper. No public API changes — all types remain re-exported at the same paths.
Merged
deepjoy
pushed a commit
that referenced
this pull request
Mar 14, 2026
## 🤖 New release * `taskmill`: 0.3.0 -> 0.3.1 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> <blockquote> ## [0.3.1](v0.3.0...v0.3.1) - 2026-03-14 ### Fixed - scheduler performance and correctness improvements ([#24](#24)) - *(taskmill)* atomic parent resolution and weak scheduler reference in TaskContext ([#22](#22)) ### Other - *(taskmill)* split large modules into focused submodules and optimize completion hot path ([#25](#25)) - *(taskmill)* add integration tests and criterion benchmarks ([#21](#21)) </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.
store.rs,scheduler/mod.rs,registry.rs,task.rs) into focused submodules organized by separation of concernscomplete()from 5 SQL statements to 3insert_history,submit_one,build_spawn_context) to remove duplicated logicDetails
Module splits
store.rsstore/{mod, submit, lifecycle, query, hierarchy, row_mapping}.rsscheduler/mod.rsscheduler/{builder, event, submit, run_loop, control, queries, tests}.rsregistry.rsregistry/{mod, context, state, child_spawner, io_tracker}.rstask.rstask/{mod, submission, typed, error, dedup, tests}.rsPerformance (completion hot path)
peek_nextuses a subquery so the partial index on(status, priority, id)acts as a covering indexcomplete_with_record/fail_with_recordvariants skip a redundantSELECT *when the caller already holds the rowjuliandayround-trip to Rustchronoarithmeticconcurrency_scaling, 7% onmixed_priority_dispatchNo public API changes — all types remain re-exported at the same paths.