Repository navigation
perf(task): avoid quadratic response history diffs - #75
Merged
earakely-scale merged 1 commit intoOct 6, 2026
Merged
Conversation
morluto
marked this pull request as ready for review
October 6, 2026 19:20
earakely-scale
approved these changes
Oct 6, 2026
Collaborator
|
Nice PR, approved. Will help get merged assuming integ tests pass |
Collaborator
|
/codebuild_run(310b0ee) |
Collaborator
|
Merging, thanks! |
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.
What and why
Closes #74.
Every completed task step diffs its context against a snapshot. The top-level list diff scans every stored response against the entire prior response list, so an unchanged history of 100 responses costs 5,050 equality comparisons; appending one response costs 5,150. This makes context bookkeeping quadratic as a run accumulates responses.
Check whether the old list is an unchanged prefix, then scan only the appended tail. Tail entries still undergo the existing membership check so duplicate appends remain no-ops. Changed or reordered prefixes retain the original behavior, including the handling of mutated response records. Deep-copy snapshots and nested metadata diffs keep their existing semantics.
Synthetic Python 3.12.12 / arm64 benchmark, measured without profiler instrumentation as the median of five batches. Each cycle includes a full context snapshot and diff, with distinct stored responses containing 512-character strings and a small structured output:
These timings measure context bookkeeping rather than complete agent runs. An approximately 246 KiB nested-metadata workload remains about 5.9 ms per cycle. The issue includes a reproduction script.
How it was tested
git diff --checkand Python syntax checks passed.The PR appears safe to merge based on the reviewed changes.
What we checked:
Summary
Context updates now scan only appended items when a saved list stays an unchanged prefix, avoiding repeated comparisons as histories grow. A comparison-count test covers unchanged and appended response histories.
Reviews (1) · Last reviewed commit: "perf(task): avoid quadratic response his..."