Thanks to visit codestin.com
Credit goes to github.com

Skip to content

refactor(taskmill): split large modules into focused submodules and optimize completion hot path#25

Merged
deepjoy merged 3 commits into
mainfrom
code-refactor
Mar 14, 2026
Merged

refactor(taskmill): split large modules into focused submodules and optimize completion hot path#25
deepjoy merged 3 commits into
mainfrom
code-refactor

Conversation

@deepjoy

@deepjoy deepjoy commented Mar 14, 2026

Copy link
Copy Markdown
Owner
  • Decompose the five largest files (store.rs, scheduler/mod.rs, registry.rs, task.rs) into focused submodules organized by separation of concerns
  • Eliminate redundant SQL in the task completion hot path, reducing complete() from 5 SQL statements to 3
  • Extract DRY helpers (insert_history, submit_one, build_spawn_context) to remove duplicated logic

Details

Module splits

Original file Lines New submodules
store.rs 2,287 store/{mod, submit, lifecycle, query, hierarchy, row_mapping}.rs
scheduler/mod.rs 1,950 → 199 scheduler/{builder, event, submit, run_loop, control, queries, tests}.rs
registry.rs 537 registry/{mod, context, state, child_spawner, io_tracker}.rs
task.rs 751 task/{mod, submission, typed, error, dedup, tests}.rs

Performance (completion hot path)

  • peek_next uses a subquery so the partial index on (status, priority, id) acts as a covering index
  • New complete_with_record / fail_with_record variants skip a redundant SELECT * when the caller already holds the row
  • Duration calculation moved from SQL julianday round-trip to Rust chrono arithmetic
  • Net: 9–16% improvement on concurrency_scaling, 7% on mixed_priority_dispatch

No public API changes — all types remain re-exported at the same paths.

deepjoy added 3 commits March 14, 2026 06:08
…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.
@deepjoy deepjoy enabled auto-merge (squash) March 14, 2026 13:38
@deepjoy deepjoy merged commit ee5db26 into main Mar 14, 2026
1 check passed
@github-actions github-actions Bot mentioned this pull request Mar 14, 2026
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>
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