Skip to content

Skip sequence checks for plain object annotations - #4341

Draft
markstuart-oai wants to merge 1 commit into
mainfrom
perf/skip-object-sequence-checks
Draft

markstuart-oai wants to merge 1 commit into
mainfrom
perf/skip-object-sequence-checks

Conversation

@markstuart-oai

@markstuart-oai markstuart-oai commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Changes being requested

Skipping three checks on plain object annotations has been saving about 2.25 ms on a 128-row inline eval in both clients. With eight fields per row, each client has been making 9,216 unnecessary checks for a list, iterable or sequence annotation.

I’ve been skipping the three checks only for the exact built-in object annotation. Both paths have been continuing to dump models and apply field formats. The test has been checking date formatting and list values in both clients. Neither path has been caching caller data.

Additional context & links

I’ve been timing the public client.evals.runs.create call through the returned typed result with an in-memory HTTPX2 transport on Linux and Python 3.12. I’ve been comparing this patch alone against f2b2399, without contacting a server.

Request Main This patch Paired change [95% interval]
32 rows, sync 2.792 ms 2.219 ms −20.6% [−20.9, −20.0]
32 rows, async 2.843 ms 2.273 ms −20.0% [−21.1, −19.3]
128 rows, sync 9.444 ms 7.193 ms −24.0% [−24.5, −22.9]
128 rows, async 9.639 ms 7.379 ms −23.6% [−24.0, −22.7]
Responses, one tool, sync 0.829 ms 0.826 ms −0.7% [−1.0, +0.3]
Responses, one tool, async 0.854 ms 0.854 ms +0.1% [−0.3, +0.7]

I’ve been rotating the order across 16 blocks on one CPU, keeping 40 calls per case per process after six warmups and resampling whole blocks. The outgoing bytes and serialized results have been matching between revisions. With just two fields per row, the 128-row saving has been ranging from 11% to 15% across Python 3.10–3.14, sync and async.

On a two-request agent task with one tool and mock HTTP, I haven’t been seeing a reliable speedup. I’ve been comparing the patch to two separate launches of main using the same import path in 24 blocks. The paired changes have been measuring −0.30% [−0.51, +0.16] and −0.45% [−0.71, +0.81].

In the Agents SDK’s 83 offline comparisons with Codex off, I’ve been checking the patch against the same Agents revision with unmodified client main. The upper end of the 95% interval has been staying below a 3% slowdown for 82 of 83 medians and 39 of 47 p95 estimates. Only the four HTTP workloads have been reaching this branch. None of those four has been showing a clear median speedup. The eval batch above has been exercising many more plain object fields.

I’ve been using 32 paired processes, with 64 fresh pairs when the protocol calls for confirmation, and 5,000 resamples of whole pairs for each interval. I haven’t been adjusting across rows. Four median intervals have been showing small increases (0.38–1.04%). All four have been including zero or favoring the patch in separate 128-pair checks. Both SQLite writes have been staying within 3% in 256 new pairs. In the 16-call tool test, throughput has been changing by +0.20% [−0.79, +0.68] in 128 pairs.

The 32-concurrent diagnostic has been showing a p95 increase of +1.70% [+0.48, +3.95] in 128 pairs. In 512 fresh pairs the change has been going the other way, −1.15% [−1.92, −0.24]. A second copy of main has been measuring +1.12% [+0.28, +2.30] against main. In two checks of all 1,024 calls, the diagnostic hasn’t been entering the changed converter. I haven’t been attributing either direction to the patch.

For the four-turn case with 1,024 items, even two copies of main have been differing by +3.12% [−2.65, +9.84] at p95. I haven’t been counting the patch’s −8.63% as a benefit.

I’ve also been checking the mean of three requests with large tool outputs. In the first 32 pairs, the change has been measuring +2.70% [+0.73, +3.86] without streaming and +3.51% [+0.51, +4.97] with streaming. In the separate 64 confirmation pairs the changes have been measuring −0.69% [−1.31, −0.05] and +0.11% [−0.44, +0.97]. In 128 new pairs, the changes have been measuring −0.24% [−1.08, +0.84] and −0.51% [−2.79, +0.79]. The two copies of main have been differing by −0.25% [−1.67, +0.51] and −0.23% [−0.92, +0.17] in that last check.

In a separate ten-block test of a long-lived process, I’ve been seeing +14.45% [+0.46, +26.72] from launch to the first answer on the patch alone. In a 48-block launch check, I’ve been loading main twice and the patch once from the same absolute path. Both launches of main have been using the same primed files, with separate files for the patch. The changes have been measuring +1.43% [−1.67, +5.11] and −0.55% [−3.02, +2.71] against those two launches of main. I haven’t been reproducing a 14% change, though those measurements have been leaving room for smaller differences.

Longer check of the one-tool task against two launches of main

I’ve been sending 3,300 changing tasks per process. In the 24 planned blocks I haven’t been seeing a consistent change in launch or in the last 200 calls against both launches of main. The two references have been loading the same source and primed bytecode. The launch intervals have still been allowing substantial slowdowns. I’ve been showing the paired percentage changes and 95% intervals separately.

Blocks Window Patch vs first main Patch vs second main
24 blocks Launch to first answer −2.50% [−5.59, +9.42] +10.81% [−0.79, +22.35]
24 blocks 101–300 −1.40% [−2.80, +0.00] −0.55% [−0.82, +0.94]
24 blocks 3,101–3,300 −0.86% [−1.54, −0.37] −0.76% [−2.01, +0.23]
18 uninterrupted blocks Launch to first answer +0.58% [−5.07, +12.87] +6.57% [−6.96, +22.35]
18 uninterrupted blocks 101–300 −1.40% [−2.48, +0.61] −0.50% [−1.00, +1.51]
18 uninterrupted blocks 3,101–3,300 −1.12% [−1.71, −0.38] −0.30% [−1.63, +0.53]
6 extra blocks Launch to first answer +8.50% [+1.01, +79.29] +19.02% [−14.23, +31.35]
6 extra blocks 101–300 −0.05% [−3.30, +73.22] +0.43% [−7.81, +6.12]
6 extra blocks 3,101–3,300 −0.88% [−12.69, +125.73] +51.56% [−5.47, +118.58]

On one of the four CPUs I’ve been waiting up to 15 minutes instead of two for the same 80% idle check after a timeout between groups. I’ve been keeping the same CPU, order and every original observation. The 18 uninterrupted blocks have been showing the subset on the other three CPUs. The six extra blocks have been serving as a separate check on a fifth CPU. I haven’t been pooling those results.

Separate follow-ups, with a duplicate main as a control
Case Metric Pairs each Patch vs main [95% interval] Second main vs main [95% interval]
concurrent5 2x128 p50 128 -0.85% [-2.08, +1.73] +0.11% [-1.32, +1.84]
retained_2048 p50 128 +0.02% [-0.17, +0.27] +0.22% [-0.13, +0.49]
time_1024_4096 p50 256 -0.60% [-1.70, +0.64] -0.49% [-1.76, +0.78]
time_2_256 p50 256 +0.95% [-0.87, +2.68] +0.41% [-0.60, +2.64]
tools4 p50 128 -0.99% [-2.12, -0.15] -0.14% [-1.76, +1.30]
warm p50 128 -0.19% [-0.89, +0.36] -0.06% [-0.34, +0.31]
diag_32 p95 128 +1.70% [+0.48, +3.95] -1.47% [-3.46, +1.13]
handoffs_12 p95 128 -0.19% [-1.09, +0.90] +0.27% [-1.13, +1.19]
history120 p95 128 -0.63% [-2.77, +1.73] -0.31% [-1.59, +2.84]
mixed_6 p95 128 -0.57% [-3.35, +0.43] -0.18% [-1.26, +0.98]
retained_2048 p95 128 -0.80% [-3.11, +2.43] +0.57% [-1.98, +2.42]
schemas_24 p95 128 -0.28% [-1.00, +0.48] +0.67% [-1.10, +2.66]
tail 4x1024 p95 128 -8.63% [-14.83, -4.92] +3.12% [-2.65, +9.84]
warm p95 128 -0.24% [-2.81, +1.23] -0.19% [-2.05, +2.06]

I’ve been comparing 41,730 paired cases near Python’s recursion limit across 3.10–3.14. The two versions have been agreeing on successes, failures, exception details and all 4,428 transmitted request bodies.

On Python 3.12, the full client suites have been passing 21,626 tests with Pydantic 2 (205 skipped) and 21,610 with Pydantic 1 (221 skipped, repository v1 exclusions). With Agents at cecd9eb and this client patch, the full Agents suite has been passing 12,874 tests (30 skipped). Formatting, Ruff, ty, import checks and package checks have been passing. With the host’s package mirror, uv lock --check has been asking for a refresh on both versions. With the index named in the lockfile, uv lock --check --offline --default-index https://pypi.org/simple has been passing on both without downloading anything or changing any file. One of ten Node tooling tests has been failing on both versions when the installer tries to fetch JSR metadata. The client suites have been using the pinned local test server.

One-process reproduction for the 128-row sync case
"""One offline sync check. Use the same environment and interpreter on both client revisions."""
import json
import statistics
import time

import httpx2
import openai

seen = []


def handle(request):
    seen.append(request.content)
    return httpx2.Response(200, content=body, headers={"content-type": "application/json"})


times = []
with openai.OpenAI(
    api_key="unused",
    base_url="https://offline.invalid/v1",
    max_retries=0,
    http_client=httpx2.Client(transport=httpx2.MockTransport(handle)),
) as client:
    for seed in range(46):
        rows = [
            {"item": {"question": f"question {seed}/{i}", "reference": f"answer {i}",
                      "language": "en", "category": "sample", "weight": 0.5,
                      "index": i, "flag": True, "optional": None}}
            for i in range(128)
        ]
        data = {"type": "jsonl", "source": {"type": "file_content", "content": rows}}
        reply = dict(id="run_offline", created_at=1770000000, data_source=data,
                     error={"code": "", "message": ""}, eval_id="eval_offline", model="offline",
                     name="sample", object="eval.run", metadata=None, per_model_usage=[],
                     per_testing_criteria_results=[], report_url="https://offline.invalid/",
                     result_counts={"errored": 0, "failed": 0, "passed": 0, "total": 128},
                     status="queued")
        body = json.dumps(reply, separators=(",", ":")).encode()
        start = time.perf_counter_ns()
        result = client.evals.runs.create(eval_id="eval_offline", data_source=data)
        times.append(time.perf_counter_ns() - start)
        assert json.loads(seen.pop()) == {"data_source": data}
        assert result.model_dump(mode="json", exclude_unset=True) == reply

print(openai.__file__, statistics.median(times[6:]) / 1e6, "ms")
All 83 paired medians
Case Cohort Pairs Main (ms) Patch (ms) Paired change [95% interval]
cold_normal primary:0-31 32 61.892 62.203 +0.74% [-0.00, +2.08]
cold_stream primary:0-31 32 253.3 252.37 -0.40% [-3.09, +0.55]
ids_17x32769 confirmation:32-95 64 68.562 68.203 -0.33% [-1.33, +0.55]
ids_17x32769_stream confirmation:32-95 64 91.216 91.218 +0.05% [-0.50, +0.80]
ids_3x8193 primary:0-31 32 5.6688 5.6348 -0.14% [-1.18, +1.15]
ids_3x8193_stream primary:0-31 32 7.9398 7.9097 -0.74% [-1.74, +0.94]
reuse_normal primary:0-31 32 38.245 38.251 -0.01% [-1.38, +0.98]
reuse_stream primary:0-31 32 39.002 39.104 -0.38% [-1.52, +0.96]
typed_3x257 primary:0-31 32 6.154 6.1215 -0.63% [-1.14, +1.19]
typed_3x257_stream primary:0-31 32 6.9222 6.9368 +0.05% [-0.72, +1.13]
add_tool primary:0-31 32 1.6905 1.6927 +0.46% [-0.13, +0.64]
build_dict_12 primary:0-31 32 0.052295 0.052192 -0.26% [-0.85, +0.31]
build_omitted_12 primary:0-31 32 0.07053 0.070137 -0.49% [-1.03, -0.03]
build_typed_12 primary:0-31 32 0.039033 0.038978 -0.10% [-0.69, +0.32]
con1 primary:0-31 32 0.49343 0.49181 -0.48% [-0.94, +0.88]
con32 primary:0-31 32 11.849 11.867 +0.81% [-0.12, +1.60]
con8 primary:0-31 32 2.8358 2.8392 -0.17% [-0.68, +1.00]
diag_32 primary:0-31 32 11.885 11.988 +0.71% [-0.39, +1.32]
h128 primary:0-31 32 1.2387 1.2421 +0.32% [-0.15, +0.70]
handoffs_0 primary:0-31 32 0.48946 0.49039 -0.21% [-0.67, +1.09]
handoffs_12 primary:0-31 32 0.69644 0.69531 +0.23% [-1.39, +1.02]
history120 primary:0-31 32 0.91064 0.90949 +0.01% [-0.61, +0.41]
history2000 primary:0-31 32 6.1039 6.1112 +0.31% [-0.79, +0.76]
history720 primary:0-31 32 2.6605 2.6728 +0.23% [-0.41, +0.81]
mixed_6 primary:0-31 32 0.70003 0.7024 +0.08% [-0.81, +1.46]
nested67_stream16 primary:0-31 32 74.355 74.085 -0.32% [-1.37, +0.60]
repeat_8 primary:0-31 32 0.98641 0.9881 -0.02% [-0.50, +0.37]
retained_16384 primary:0-31 32 0.20664 0.2096 -0.69% [-1.59, -0.09]
retained_2048 primary:0-31 32 0.029409 0.029739 +1.04% [+0.72, +1.39]
run_dict_6 primary:0-31 32 0.7679 0.76394 -0.13% [-0.71, +0.28]
run_omitted_6 primary:0-31 32 0.81636 0.81614 +0.12% [-0.38, +0.84]
run_typed_6 primary:0-31 32 0.7339 0.73171 -0.54% [-1.20, +0.12]
schemas_24 primary:0-31 32 0.84533 0.84859 +0.55% [-0.29, +1.05]
server_1 primary:0-31 32 1.7782 1.7785 -0.20% [-0.63, +0.47]
server_1024 primary:0-31 32 20.845 20.988 +0.21% [-0.84, +1.28]
server_128 primary:0-31 32 4.3413 4.3701 +0.52% [-0.58, +1.41]
server_512 primary:0-31 32 11.427 11.551 +0.76% [-0.55, +2.07]
single_0 primary:0-31 32 0.48647 0.49055 +0.27% [-0.29, +0.97]
single_12 primary:0-31 32 0.57396 0.57029 +0.02% [-0.96, +0.32]
stream primary:0-31 32 0.76369 0.76827 +0.40% [-0.16, +1.24]
sustained_32 primary:0-31 32 11.922 11.755 -0.95% [-1.65, +0.56]
time_1024_4096 confirmation:32-95 64 51.54 51.246 -1.71% [-3.52, +1.80]
time_16384_2 primary:0-31 32 0.41107 0.41277 +0.15% [-0.08, +0.61]
time_2048_2 primary:0-31 32 0.058039 0.058009 -0.08% [-0.44, +0.30]
time_2_256 confirmation:32-95 64 6.01 6.1982 +0.29% [-3.51, +6.71]
time_4096_8 primary:0-31 32 0.43962 0.43996 -0.07% [-0.37, +0.18]
tools1 primary:0-31 32 1.5772 1.5817 +0.02% [-0.33, +0.78]
tools16 primary:0-31 32 18.987 19.017 +0.32% [-0.15, +0.76]
tools4 primary:0-31 32 4.5357 4.5616 +0.38% [+0.07, +0.90]
warm primary:0-31 32 0.48192 0.48296 +0.66% [+0.04, +1.13]
batch-compare 1x1024 primary:0-31 32 21.095 21.026 -0.14% [-0.76, +0.13]
batch-compare 2x32 primary:0-31 32 3.6784 3.6896 +0.30% [-0.11, +0.57]
bulk-live 12x64 primary:0-31 32 16.308 16.246 -0.50% [-1.05, +0.17]
bulk-live 1x1024 primary:0-31 32 21.27 20.972 -1.21% [-1.65, -0.07]
bulk-live 1x2048 primary:0-31 32 40.269 40.153 -0.65% [-1.70, +0.01]
bulk-live 1x256 primary:0-31 32 6.8437 6.7556 -0.80% [-1.93, -0.48]
combo5 4x1024 primary:0-31 32 44.22 44.306 +0.50% [-0.11, +0.92]
combo5 8x128 primary:0-31 32 36.444 36.25 -0.45% [-1.18, +0.52]
concurrent5 2x128 confirmation:32-95 64 417.85 424.55 +0.98% [+0.05, +2.24]
first-final 1x0 primary:0-31 32 1565.9 1574.6 +0.26% [-0.25, +0.88]
first-mcp 1x0 primary:0-31 32 1562.3 1560.8 +0.02% [-0.48, +0.86]
lists-final 1x1024 primary:0-31 32 5.3276 5.3505 +0.01% [-1.80, +1.46]
lists-final 8x8192 primary:0-31 32 35.519 35.332 -0.27% [-2.21, +1.32]
provider-final 1x2048 primary:0-31 32 262.16 262.59 +0.06% [-0.66, +0.37]
provider-final 1x4096 primary:0-31 32 519.07 521.36 +0.14% [-0.36, +0.91]
quote-final 1x1 primary:0-31 32 1.6917 1.6868 -0.15% [-0.49, +0.02]
quote-final 1x64 primary:0-31 32 2.5881 2.5674 -0.36% [-0.59, -0.01]
quote-final 8x16 primary:0-31 32 11.393 11.316 -0.48% [-1.04, +0.24]
quote-final 8x256 primary:0-31 32 36.897 36.764 -0.01% [-0.81, +0.39]
quote-final 8x64 primary:0-31 32 16.697 16.643 -0.20% [-1.03, +0.10]
shape-local normal 12x96 primary:0-31 32 34.739 34.989 +0.28% [-0.06, +0.65]
shape-local stream 12x96 primary:0-31 32 57.022 56.768 -0.03% [-1.14, +0.68]
shape-local stream 4x12 primary:0-31 32 11.532 11.545 +0.37% [-0.57, +1.15]
shape-local stream 8x0 primary:0-31 32 14.45 14.538 +0.17% [-0.38, +0.96]
tail 4x1024 confirmation:32-95 64 43.353 43.393 +0.18% [-0.17, +0.34]
values-final ids 1x1 primary:0-31 32 1.6423 1.6395 -0.10% [-0.39, +0.25]
values-final ids 8x8192 primary:0-31 32 12.583 12.677 +0.42% [-0.48, +1.60]
values-final last 4x512 primary:0-31 32 5.9992 5.9914 -0.24% [-0.86, +0.19]
values-final records 8x512 primary:0-31 32 11.063 11.075 +0.37% [-0.17, +0.95]
values-final typed 16x1024 primary:0-31 32 26.799 26.674 -0.17% [-0.99, +0.39]
values-final typed 4x128 primary:0-31 32 4.9472 4.9514 +0.18% [-0.30, +0.95]
warm-control 1x0 primary:0-31 32 1.6797 1.6758 +0.04% [-0.32, +0.45]
warm-control 1x4096 primary:0-31 32 35.136 35.235 -0.33% [-1.41, +0.48]
All 47 p95 estimates, including separate cohorts
Case Cohort Pairs Main (ms) Patch (ms) Paired change [95% interval]
add_tool primary 32 1.8227 1.7882 +0.17% [-1.60, +1.74]
build_dict_12 primary 32 0.087945 0.085983 -0.08% [-3.31, +2.40]
build_omitted_12 primary 32 0.11005 0.10837 -0.97% [-1.97, +0.38]
build_typed_12 primary 32 0.068406 0.067651 -0.39% [-2.18, +0.58]
con1 primary 32 0.54079 0.53594 +0.34% [-1.21, +1.49]
con32 primary 32 75.488 72.946 -0.88% [-7.82, +2.25]
con8 primary 32 3.1108 3.1291 -0.12% [-1.31, +1.08]
diag_32 primary 32 61.511 63.055 +2.88% [-0.86, +6.10]
h128 primary 32 1.5006 1.4229 -2.86% [-5.73, +0.77]
handoffs_0 primary 32 0.55747 0.55016 -1.29% [-4.27, +1.56]
handoffs_12 primary 32 0.74429 0.74191 +0.03% [-1.17, +3.34]
history120 primary 32 0.93787 0.95905 +0.74% [-0.33, +5.45]
history2000 primary 32 6.3702 6.3221 +0.18% [-2.05, +2.00]
history720 primary 32 2.8934 2.8847 -1.21% [-2.68, +1.52]
mixed_6 primary 32 0.75597 0.76287 +0.62% [-0.42, +3.08]
repeat_8 primary 32 1.0583 1.0331 -1.24% [-2.55, +0.56]
retained_16384 primary 32 0.23048 0.23118 -0.55% [-1.28, +0.84]
retained_2048 primary 32 0.046394 0.046664 +0.05% [-2.40, +4.17]
run_dict_6 primary 32 0.81422 0.82509 +0.42% [-1.56, +1.69]
run_omitted_6 primary 32 0.8773 0.87773 +0.07% [-1.47, +2.05]
run_typed_6 primary 32 0.7971 0.78729 -1.86% [-4.28, +0.60]
schemas_24 primary 32 0.90207 0.90378 -0.63% [-3.72, +3.08]
server_1 primary 32 1.8719 1.8572 -0.79% [-2.55, +0.50]
single_0 primary 32 0.54545 0.55658 +0.58% [-2.65, +2.38]
single_12 primary 32 0.62134 0.61863 -0.67% [-2.26, +0.45]
stream primary 32 0.90673 0.91021 +0.60% [-0.70, +1.91]
sustained_32 primary 32 61.325 59.723 -3.68% [-6.88, +1.56]
time_16384_2 primary 32 0.4258 0.42484 -0.17% [-0.85, +1.14]
time_2048_2 primary 32 0.080394 0.080735 +0.33% [-1.33, +1.57]
time_4096_8 primary 32 0.45997 0.45845 -0.43% [-1.49, +0.42]
tools1 primary 32 1.6544 1.6605 +0.81% [-0.33, +2.53]
tools16 primary 32 19.395 19.683 -0.20% [-1.07, +1.77]
tools4 primary 32 4.7772 4.7909 +0.23% [-2.95, +2.35]
warm primary 32 0.52951 0.54633 +1.11% [-0.56, +6.16]
batch-compare 2x32 primary 32 3.7832 3.7631 +0.24% [-0.80, +0.76]
bulk-live 12x64 primary 32 16.9 16.722 -0.26% [-3.69, +1.14]
bulk-live 1x256 primary 32 7.3947 7.1632 -2.63% [-5.17, -0.91]
quote-final 1x1 primary 32 1.7483 1.7361 -0.52% [-1.04, +0.44]
quote-final 1x64 primary 32 2.666 2.673 +0.15% [-1.73, +1.44]
quote-final 8x16 primary 32 11.958 11.772 -0.30% [-2.66, +0.99]
quote-final 8x256 primary 32 40.971 38.603 -4.75% [-6.42, +1.16]
quote-final 8x64 primary 32 17.293 17.008 -1.43% [-6.82, +0.37]
tail 4x1024 primary 32 47.158 48.48 +1.74% [-1.14, +7.09]
values-final ids 1x1 primary 32 1.6889 1.6982 -0.08% [-0.88, +1.20]
warm-control 1x0 primary 32 1.7748 1.7621 +0.86% [-1.93, +1.33]
warm-control 1x4096 primary 32 88.625 87.124 -1.39% [-5.59, +1.22]
tail 4x1024 confirmation 64 49.128 46.082 -4.91% [-13.03, -1.81]

This branch has not been deployed

No deployments
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