Skip to content

Reduce processing time for large function tool results - #6217

Merged
markstuart-oai merged 1 commit into
mainfrom
perf/typed-function-tool-results
Nov 25, 2026
Merged

markstuart-oai merged 1 commit into
mainfrom
perf/typed-function-tool-results

Conversation

@markstuart-oai

Copy link
Copy Markdown
Contributor

Summary

In the offline HTTP replay, eight calls returning large lists have been dropping from 57 to 36 ms. In the scripted Runner, 16 calls returning text blocks have been dropping from 82 to 29 ms. Little change on a single small result.

Function tools have been spending time building a validation model for each text block and copying the entire result even without a custom data extractor.

With this change, the SDK has been building fresh output blocks directly for plain dictionaries with exactly two valid text fields. Other shapes have been going through the existing validator. On a non-structured item, the SDK has been falling back to the original list or tuple as a whole.

The SDK has been making a detached copy only for a configured extractor. Metadata from the tool context has been working with or without an extractor.

Related work in #6195 on plain lists. The text-block conversion and conditional extractor copy have also been helping with structured results.

Benchmarks

Complete request Main, ms PR, ms Change [95% interval]
16 tool calls with 1,024 text blocks each 82.22 28.75 -65.28% [-65.57, -64.80]
8 calls returning 8,192 integers each 33.47 13.21 -60.76% [-61.23, -59.94]
Same integer lists through the Responses HTTP client 57.39 36.16 -37.12% [-38.41, -35.77]
4 calls with mixed 512-item lists 10.4 6.264 -39.57% [-40.32, -39.06]
One call returning one integer 1.722 1.707 -0.89% [-1.42, -0.50]
32 concurrent streams, second batch 380.7 369.7 -2.61% [-4.18, -1.82]
32 concurrent streams, sum of three timed batches 1358 1334 -2.03% [-2.66, -1.14]

A separate 18-pair HTTP replay of the large integer lists with a mock transport has been reproducing the gain (57.0 to 36.3 ms, −37.3%). For typed text, the six timed runs at the end of the original test sequence have been dropping from 53.7 to 47.5 ms in total. All six have been improving, including the second ordinary run (6.63 to 5.47 ms) and the second streamed run (8.40 to 6.94 ms).

Still uncertain — the two SQLite writes. In the independent repeats, the large write has been measuring +2.63% [−2.43, +6.90] and the small one +1.33% [−3.33, +5.25]. Both intervals have been crossing zero and the +3% threshold. No SQLite changes.

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 main at 4e162c79, without network or model latency.

95% interval versus a 3% slowdown Within margin Uncertain Above margin
Initial, all 83 79 4 0
Independent repeat, 5 selected 3 2 0
Latest result per workload 81 2 0
Timings and 95% intervals for all 83 comparisons
  • Initial — 32 matched pairs of fresh processes, balanced by run order.
  • Repeat — 64 new pairs for every initial upper bound above +3%, both SQLite writes and 32 concurrent streams. No pooling.
  • Main / PR — median elapsed time in milliseconds, from the repeat where available. For repeated calls, the median across process medians. For 32 streams, the median of three timed batches.
  • Change — median within-pair percentage change, with 95% bounds from 5,000 resamples of whole pairs. Negative for faster. Calculated from individual pairs before taking the median.
  • Margin — within for an upper bound ≤ +3%, above for a lower bound > +3%, otherwise uncertain. A result within the margin can include a small slowdown. Individual intervals only, without correction for multiple comparisons.
Workload Main, ms PR, ms Initial % [95% interval] Repeat % [95% interval]
Fresh-agent control, normal 41.284 41.46 -0.89 [-4.42, +2.52] —
Fresh-agent control, streaming 278.7 278.23 +0.22 [-1.87, +1.72] —
Integer-list output, 17 calls, 32769 initial entries, normal 237.37 64.866 -72.48 [-72.72, -72.33] —
Integer-list output, 17 calls, 32769 initial entries, streaming 263.33 91.324 -65.44 [-65.82, -64.70] —
Integer-list output, 3 calls, 8193 initial entries, normal 13.188 5.6637 -57.28 [-57.81, -56.70] —
Integer-list output, 3 calls, 8193 initial entries, streaming 16.372 8.7631 -46.62 [-47.80, -45.22] —
Reused-agent control, normal 38.714 38.344 +0.25 [-2.87, +1.95] —
Reused-agent control, streaming 39.564 39.53 -0.59 [-1.33, +1.20] —
Typed text-list output, 3 calls, 257 initial entries, normal 6.6581 5.5466 -16.56 [-17.82, -14.95] —
Typed text-list output, 3 calls, 257 initial entries, streaming 8.1945 7.1182 -12.61 [-13.67, -11.72] —
Dynamic tool addition 1.7217 1.7147 -0.39 [-0.68, +0.26] —
Agent with 12 tools, dictionary settings, construction only 0.051608 0.051417 -0.03 [-0.66, +0.33] —
Agent with 12 tools, default settings, construction only 0.070602 0.070516 +0.12 [-0.80, +0.79] —
Agent with 12 tools, typed settings, construction only 0.038378 0.038345 +0.05 [-0.51, +0.33] —
Concurrent runs, 1 task 0.50682 0.50464 -0.86 [-1.55, +0.35] —
Concurrent runs, 32 tasks 12.443 12.34 -0.24 [-1.56, +2.60] —
Concurrent runs, 8 tasks 2.9215 2.9398 +0.41 [-0.90, +1.06] —
32 concurrent runs with GC observation 12.103 12.2 +0.43 [-0.55, +1.20] —
Stream completion, 128 history messages 1.2636 1.2628 +0.40 [-0.40, +1.15] —
0 available handoffs 0.49365 0.49582 +0.23 [-0.41, +0.91] —
12 available handoffs 0.70913 0.70248 -0.88 [-1.16, +0.11] —
Input history, 120 messages 0.93519 0.93948 +0.94 [-0.32, +1.56] —
Input history, 2000 messages 6.2307 6.2984 +0.10 [-1.39, +2.39] —
Input history, 720 messages 2.6486 2.6474 -0.17 [-1.64, +0.31] —
6 handoff routes, mixed agent names 0.73305 0.72732 -0.52 [-1.06, +0.47] —
Structured streamed response, 67 fields, 16 tool turns 75.211 75.278 -0.52 [-1.24, +1.41] —
8 handoff routes, repeated agent names 1.0104 1.0116 -0.22 [-0.65, +0.43] —
Retained history, 16384 existing + 1 new message 0.41058 0.40923 +0.25 [-1.00, +0.82] —
Retained history, 2048 existing + 1 new message 0.053626 0.05329 -0.63 [-0.84, +0.19] —
Agent with 6 tools, dictionary settings, construction + run 0.77854 0.77678 +0.27 [-0.95, +0.77] —
Agent with 6 tools, default settings, construction + run 0.83147 0.83221 -0.24 [-0.64, +0.80] —
Agent with 6 tools, typed settings, construction + run 0.74228 0.74557 +0.49 [-0.41, +0.76] —
24 available tool schemas 0.85122 0.85406 +0.29 [-0.15, +1.00] —
Server-managed conversation, 1 history message 1.8368 1.8191 -0.73 [-1.77, +0.06] —
Server-managed conversation, 1024 history messages 35.341 35.472 +0.88 [-1.23, +1.90] —
Server-managed conversation, 128 history messages 4.6426 4.6237 -0.18 [-1.34, +3.34] -0.16 [-0.79, +0.55]
Server-managed conversation, 512 history messages 15.356 15.559 +0.87 [-1.67, +1.62] —
0 handoff routes, distinct agent names 0.50526 0.49632 -0.40 [-1.66, +0.09] —
12 handoff routes, distinct agent names 0.59444 0.58916 -0.95 [-1.61, +0.60] —
Streamed final response 0.79547 0.80044 +0.39 [-0.48, +1.91] —
32 sustained concurrent runs 11.963 11.964 +0.19 [-0.87, +0.99] —
SQLite committed batch, 1024 items × 4096 payload characters 59.325 60.762 +1.38 [-1.48, +6.58] +2.63 [-2.43, +6.90]
Retained history, 16384 existing + 2 new messages 0.80612 0.80147 -0.56 [-1.78, +0.09] —
Retained history, 2048 existing + 2 new messages 0.10467 0.10508 +0.32 [-1.11, +0.91] —
SQLite committed batch, 2 items × 256 payload characters 7.6376 7.8307 -0.28 [-5.06, +5.83] +1.33 [-3.33, +5.25]
Retained history, 4096 existing + 8 new messages 0.83332 0.82748 -1.15 [-2.77, -0.30] —
Tool loop, 1 turn 1.6323 1.6237 -0.21 [-1.92, +1.07] —
Tool loop, 16 turns 19.662 19.58 -0.58 [-1.96, +1.17] —
Tool loop, 4 turns 4.6662 4.6336 -1.21 [-1.82, -0.40] —
Warm final response 0.48276 0.48512 +0.16 [-1.24, +1.59] —
Tool-turn repetition control, 1 call, 1024 history messages 35.818 35.692 -0.36 [-2.17, +1.93] —
Tool-turn repetition control, 2 calls, 32 history messages 3.8176 3.8122 -0.42 [-1.35, +0.83] —
Tool turn, 12 calls, 64 history messages 17.048 17.001 -0.31 [-0.88, +0.25] —
Tool turn, 1 call, 1024 history messages 35.792 35.515 +0.16 [-1.49, +0.63] —
Tool turn, 1 call, 2048 history messages 94.573 94.023 +0.10 [-0.78, +0.61] —
Tool turn, 1 call, 256 history messages 7.9853 7.8961 -1.08 [-1.75, +0.06] —
Structured tool workload, 4 calls, 1024 history messages 59.65 59.663 +1.05 [-0.59, +2.42] —
Structured tool workload, 8 calls, 128 history messages 38.005 37.611 -0.30 [-1.38, +0.48] —
32 concurrent streams, 2 tool calls, 128 history messages 479.3 475.29 +1.07 [-0.61, +2.28] -0.41 [-1.40, +0.16]
First completed run, 1 tool turn, including launch 1144.3 1136.7 -0.51 [-2.52, +1.39] —
First completed run with empty tool server, 1 tool turn, including launch 1093.4 1090.7 -0.66 [-3.45, +3.66] -0.82 [-1.43, +0.82]
List output, 1 call × 1024 entries 5.8112 5.4816 -5.37 [-7.28, -4.59] —
List output, 8 calls × 8192 entries 57.393 36.163 -37.12 [-38.41, -35.77] —
Provider-response conversion, 1 call, 2048 history messages 318.26 318.78 +0.12 [-0.24, +1.09] —
Provider-response conversion, 1 call, 4096 history messages 757.09 753.29 +0.19 [-1.21, +1.95] —
Line-item calculation, 1 call × 1 record 1.7447 1.7432 -0.04 [-0.42, +0.98] —
Line-item calculation, 1 call × 64 records 2.6358 2.6334 +0.23 [-0.40, +0.79] —
Line-item calculation, 8 calls × 16 records 11.709 11.715 +0.13 [-0.39, +0.60] —
Line-item calculation, 8 calls × 256 records 37.575 37.449 +0.14 [-0.96, +0.75] —
Line-item calculation, 8 calls × 64 records 17.166 17.202 +0.43 [-0.35, +0.75] —
Structured response, 12 tool calls, 96 fields, normal 36.513 35.938 -0.84 [-4.68, +0.76] —
Structured response, 12 tool calls, 96 fields, stream 58.501 57.362 -0.70 [-3.15, +0.09] —
Structured response, 4 tool calls, 12 fields, stream 11.892 11.772 -0.90 [-2.46, +0.29] —
Structured response, 8 tool calls, 0 fields, stream 14.86 14.645 -1.44 [-2.52, -0.55] —
Sustained structured tool workload, 4 calls, 1024 history messages 59.786 60.307 +0.15 [-1.83, +1.59] —
Integer list, 1 call × 1 entry 1.7221 1.7068 -0.89 [-1.42, -0.50] —
Integer list, 8 calls × 8192 entries 33.469 13.212 -60.76 [-61.23, -59.94] —
Mixed list, 4 calls × 512 entries 10.404 6.2641 -39.57 [-40.32, -39.06] —
Record list, 8 calls × 512 entries 13.228 11.66 -11.61 [-12.74, -11.34] —
Typed text list, 16 calls × 1024 entries 82.22 28.75 -65.28 [-65.57, -64.80] —
Typed text list, 4 calls × 128 entries 7.2064 5.1942 -27.54 [-28.16, -27.04] —
Warm tool control, 1 call, 0 history messages 1.7581 1.7527 -0.32 [-1.23, +0.25] —
Warm tool control, 1 call, 4096 history messages 36.08 36.285 +0.82 [-1.25, +2.03] —

Test plan and checks

  • New tests for block order, independent copies, coercion and whole-list fallback. A nested mutation by an extractor with checks on the result and the next model input.
  • Full repository verifier (.agents/skills/code-change-verification/scripts/run.sh) including formatting, lint, mypy, Pyright and both pytest phases. 12,867 passed, 30 skipped.
  • Independent review of the complete diff. Identical Git tree for the local checks and PR head.

@markstuart-oai
markstuart-oai requested review from a team, rm-openai and seratch as code owners November 25, 2026 02:18
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T02:19:05.055124Z 36bd469 PR opened
🔒 Security Review ✅ Completed 2026-11-25T02:19:34.928864Z 36bd469 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

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 jbeckwith-oai left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the tool-output conversion and custom-data extraction changes, surrounding code, and regression coverage. The fast path retains validation for other inputs and returns detached output blocks; configured extractors retain deep-copy isolation. No actionable findings. Static review only; no local code or tests run. Hosted CI: 24 successful checks on this commit.

@markstuart-oai
markstuart-oai added this pull request to the merge queue Nov 25, 2026
Merged via the queue into main with commit 06044d2 Nov 25, 2026
26 checks passed
@markstuart-oai
markstuart-oai deleted the perf/typed-function-tool-results branch November 25, 2026 20:21
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.

2 participants