Repository navigation
Speed up input preparation for long conversation histories - #6220
Open
markstuart-oai wants to merge 1 commit into
Open
markstuart-oai wants to merge 1 commit into
markstuart-oai wants to merge 1 commit into
Conversation
markstuart-oai
requested review from
a team,
rm-openai and
seratch
as code owners
November 25, 2026 04:55
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
jbeckwith-oai
approved these changes
Nov 25, 2026
jbeckwith-oai
left a comment
Contributor
There was a problem hiding this comment.
Approved after comprehensive static review and independent review. The exact-dictionary deduplication shortcut only reads identity fields, and the string shortcut preserves fresh nested containers and existing custom mapping/subclass behavior. No actionable findings.
Hosted CI: 24 successful checks on this commit. No candidate code, local tests, or benchmarks were executed.
This branch has not been deployed
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
For 32 concurrent requests with 2,048 plain messages each, the median time to finish the batch has been dropping from 491 to 415 ms. For one request with 2,000 messages, this change has been saving about 1 ms. These gains have been coming from input preparation before the model call.
The SDK has been copying each message dictionary just to read its deduplication key. It has also been checking each dictionary against the generic mapping interface and making a recursive call for each string while preparing input.
With this change, the SDK has been reading keys directly from plain dictionaries and copying string values without another function call. It has been building fresh containers for each occurrence of a message, including nested content. Custom mappings, models and string subclasses have been keeping their existing conversion paths.
Benchmarks
32 concurrent requests with client-side history. A separate offline test with the same agent, a distinct history per request, one tool call and two scripted replies. Each request has been returning the completed answer and the full replay history. Six timed batches after two warmups per process, 24 matched process pairs.
For 2,048 plain messages, the total across six batches, including checks and cleanup, has been dropping from 2.89 to 2.42 seconds (−15.95%). Both sides have been doing a median of four full garbage collections during the six batches. A separate pilot with one request and 4,096 nested messages has been inconclusive. No expected reduction in model or network time.
In a third test with one tool call and 2,048 plain messages per request, elapsed time has been dropping from 11.71 to 9.65 ms (−18.5%, 95% interval −22.6 to −14.0%). The warm request with one registered tool, no tool calls and no prior messages has been measuring 0.619 ms on main and 0.637 ms on the branch (+2.9% [0.7, 4.8]). The 83-case suite's warm final response has been measuring −0.30% [−2.00, +2.65].
In 48 new blocks with warmed Python bytecode on every build, the same no-call case has been measuring −0.05% [−0.83, +0.48] on this branch. Two identical builds of main have been differing by −0.43% [−1.51, +0.18]. The test has been using every order of four builds on each of two CPUs.
Competing work on the benchmark host. During the first 83 comparisons and the independent repeats, the median one-minute load averages have been running at 80 and 49 respectively on a 32-CPU host. The 64-pair repeat has been leaving eight comparisons uncertain, including the large SQLite write at +11.53% [0.10, 21.49]. All samples have been staying in the table below.
A synchronized SQLite comparison has been rotating two copies of each build across four writer positions in 128 blocks. The large write has been measuring −0.05% [−0.38, +0.05] and the small one −3.05% [−5.81, +0.04]. Both same-code controls have been covering zero for each write size. An untimed trace has been recording zero calls to either changed helper. These results have been pointing to disk timing.
Separate run on a lightly loaded host. With four workers and 64 new process pairs, all six other uncertain comparisons and the 32-stream control have been meeting the +3% limit. No pooling or substitution in the original table.
For 32 streams, batch two has been measuring −1.68% [−2.47, −0.57], and the sum of all three −1.06% [−2.85, −0.01].
Regression checks across all 83 comparisons with Codex off. Offline Python SDK workloads on one Linux host with CPython 3.12.16. This change alone against
mainat4e162c79, without network or model latency.Timings and 95% intervals for all 83 comparisons
Test plan and checks
.agents/skills/code-change-verification/scripts/run.sh) including formatting, lint, mypy, Pyright and both pytest phases. 12,866 passed, 30 skipped.