Skip to content

Perf — Replace dataclasses.asdict() with Manual Dicts on 4 Warm Paths#2217

Merged
Trecek merged 4 commits into
developfrom
perf-replace-dataclasses-asdict-with-manual-dicts-on-4-warm/2193
May 8, 2026
Merged

Perf — Replace dataclasses.asdict() with Manual Dicts on 4 Warm Paths#2217
Trecek merged 4 commits into
developfrom
perf-replace-dataclasses-asdict-with-manual-dicts-on-4-warm/2193

Conversation

@Trecek
Copy link
Copy Markdown
Collaborator

@Trecek Trecek commented May 8, 2026

Summary

Replace return asdict(self) with explicit field dicts in the to_dict() method of four hot-path dataclasses: DispatchRecord, TokenEntry, TimingEntry, and FailureRecord. For DispatchRecord.token_usage (the single non-primitive field across all four), use dict(self.token_usage) for a shallow copy that avoids the deep-copy overhead of asdict while preserving safety for current callers. Remove asdict from the dataclasses import in all four files once it is no longer used. The cold-path AutomationConfig serialization at cli/app.py:302 is explicitly out of scope and must remain unchanged.

Requirements

Acceptance Criteria

  • All 4 warm-path to_dict() methods use explicit field dicts
  • DispatchRecord.token_usage uses shallow copy (dict(self.token_usage))
  • AutomationConfig at cli/app.py:302 keeps asdict()
  • All existing tests pass
  • JSON output is identical (verified by round-trip tests)

Changed Files

New (★):

tests/fleet/test_state_schema.py
tests/pipeline/test_audit.py

Modified (●):

src/autoskillit/core/types/_type_results.py
src/autoskillit/fleet/state_types.py
src/autoskillit/pipeline/timings.py
src/autoskillit/pipeline/tokens.py

Closes #2193

Implementation Plan

Plan file: /home/talon/projects/autoskillit-runs/impl-20260507-215724-984456/.autoskillit/temp/make-plan/perf_replace_asdict_plan_2026-05-07_220015.md

🤖 Generated with Claude Code via AutoSkillit

Token Usage Summary

Step Model count uncached output cache_read peak_ctx turns cache_write time
plan claude-sonnet-4-6 1 107 10.0k 340.2k 61.7k 40 32.2k 4m 19s
verify claude-sonnet-4-6 1 68 8.6k 256.7k 46.2k 42 33.3k 4m 32s
implement* MiniMax-M2.7-highspeed 1 1.2M 6.5k 831.6k 29.8k 77 16.3k 2m 48s
prepare_pr* MiniMax-M2.7-highspeed 1 73.3k 3.7k 205.7k 29.8k 20 15.3k 1m 34s
compose_pr* MiniMax-M2.7-highspeed 1 28.6k 1.5k 146.1k 29.8k 14 15.1k 45s
review_pr claude-sonnet-4-6 3 294 76.4k 1.4M 66.4k 109 154.8k 15m 14s
resolve_review claude-sonnet-4-6 3 491 25.2k 2.4M 58.6k 148 124.0k 16m 15s
Total 1.3M 132.1k 5.5M 66.4k 391.0k 45m 31s

* Step used a non-Anthropic provider; caching behavior may differ.

Token Efficiency

Step LoC Changed cache_read/LoC cache_write/LoC output/LoC
plan 0
verify 0
implement 136 6114.4 119.6 48.1
prepare_pr 0
compose_pr 0
review_pr 0
resolve_review 6 399185.0 20664.0 4204.8
Total 142 38964.3 2753.4 930.5

Model Usage Breakdown

Model steps uncached output cache_read cache_write time
claude-sonnet-4-6 2 175 18.7k 596.9k 65.5k 8m 52s
MiniMax-M2.7-highspeed 3 1.3M 11.8k 1.2M 46.7k 5m 8s

Trecek and others added 4 commits May 7, 2026 22:52
Replace `return asdict(self)` with explicit field dicts in the to_dict()
method of DispatchRecord, TokenEntry, TimingEntry, and FailureRecord.
For token_usage on DispatchRecord, use dict(self.token_usage) for a
shallow copy. Removes deep-copy overhead on hot-path serialization.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Docstring "must return all 17 keys" will silently lie when fields are
added or removed. Changed to "must return all expected keys" — the
assertion set already enforces correctness without the stale count.
…_to_dict_token_usage_is_shallow_copy

Comments restated what the is/is not assertions already express.
@Trecek Trecek added this pull request to the merge queue May 8, 2026
Merged via the queue into develop with commit e1d139b May 8, 2026
2 checks passed
@Trecek Trecek deleted the perf-replace-dataclasses-asdict-with-manual-dicts-on-4-warm/2193 branch May 8, 2026 07:16
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