Perf — Replace dataclasses.asdict() with Manual Dicts on 4 Warm Paths#2217
Merged
Trecek merged 4 commits intoMay 8, 2026
Merged
Conversation
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.
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
Replace
return asdict(self)with explicit field dicts in theto_dict()method of four hot-path dataclasses:DispatchRecord,TokenEntry,TimingEntry, andFailureRecord. ForDispatchRecord.token_usage(the single non-primitive field across all four), usedict(self.token_usage)for a shallow copy that avoids the deep-copy overhead ofasdictwhile preserving safety for current callers. Removeasdictfrom thedataclassesimport in all four files once it is no longer used. The cold-pathAutomationConfigserialization atcli/app.py:302is explicitly out of scope and must remain unchanged.Requirements
Acceptance Criteria
to_dict()methods use explicit field dictsDispatchRecord.token_usageuses shallow copy (dict(self.token_usage))AutomationConfigatcli/app.py:302keepsasdict()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 used a non-Anthropic provider; caching behavior may differ.
Token Efficiency
Model Usage Breakdown