Repository navigation
Defer unused aiohttp imports and speed up request body conversion - #4332
Draft
markstuart-oai wants to merge 1 commit into
Draft
markstuart-oai wants to merge 1 commit into
markstuart-oai wants to merge 1 commit into
Conversation
| import httpx2 | ||
| import pytest | ||
|
|
||
| import openai |
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.
Changes being requested
Applications with the aiohttp extra installed have been paying to import its transport even when they use the default HTTP client. The default client has been able to work without that import. The SDK now loads the transport when the application constructs the optional client or requests the vendored transport directly. Applications that select aiohttp still pay that cost on first use.
On every request, the sync and async clients have also been walking the type annotations of plain strings, numbers, booleans and nulls inside typed dictionaries. Those values already have their JSON representation. The client now applies the field alias and passes exact built-in scalars through. Subclasses, dates, files, models, collections, omitted fields and unknown keys keep their existing paths. No user values or schemas have been entering a new cache.
Additional context & links
With aiohttp installed and the default HTTP client selected, process launch to a checked one-tool answer has been falling from 864 to 752 ms. The paired median saving across 16 pairs has been 109 ms (95% interval 91–118 ms). Fifteen pairs have been improving. Applications without the optional dependency have been seeing little change in startup.
With the Agents SDK fixed at its main revision, 12 paired blocks through the Responses adapter have been showing the following times.
Across 83 Codex-off comparisons, 82 medians have been meeting the 3% slowdown limit. One result remains inconclusive. No interval lies wholly above the limit. The comparison combines both Python changes against openai/openai-agents-python at
6afdd47band openai/openai-python at66266569. It cannot isolate the effect of either PR. Each row uses 32 primary pairs. In 4 prespecified or uncertain rows, the reported estimate uses 64 new pairs without pooling samples.The 32-stream workload has been taking 355.4 ms per batch against 410.3 ms on main (paired −12.79%, 95% interval −13.52% to −12.29%). The large SQLite write has been remaining inconclusive (48.92 to 49.35 ms, paired +1.98%, interval −1.11% to +3.83%). The small write has been meeting the margin on confirmation (−4.56%, interval −7.61% to +0.09%). Building an agent with 12 tools and dictionary settings has been taking 51.7 to 52.5 µs (+1.07%, interval +0.80% to +1.92%). A separate 256-request burst with 32 ordinary requests at a time has been showing a real tail cost for the combined changes. The median has been falling from 11.86 to 7.40 ms, while p95 has been rising from 13.15 to 59.55 ms in all 32 pairs.
A separate 128-block test has been synchronizing four writers using separate databases on the same storage on another host. The large write has been showing +0.009% (95% interval −0.030% to +0.052%), close to the comparisons between identical builds. The small write has been showing +0.81% (−0.67% to +3.48%). All 11,776 committed-data checks have been passing. This control leaves the original 83 results intact.
A separate 12-block Responses adapter run has been keeping the Agents testing package unloaded. Launch to answer has been taking 852.8 ms on both mains, 676.4 ms with only the Agents change and 674.0 ms with both changes. Warm medians have been taking 5.089, 4.678 and 3.671 ms respectively. This checks that the application benefit survives removal of the test helper imports. Responses have been using an intercepted transport without live inference.
In a separate short-burst check with only this client change and the Agents SDK held fixed, p95 has been measuring 12.72 ms against 13.54 ms on main. Those two diagnostic pairs have not been reproducing the combined increase. They are too few to establish a client-only tail improvement.
The measurements have been using deterministic local model replies. The provider run has been using the Responses client with an intercepted HTTP transport. Each answer has been requiring two checked requests and one tool execution. These numbers describe SDK work and exclude model inference and external network latency.
The offline suite has been passing 13,005 tests under Pydantic v2 and 12,989 under v1 (175 and 191 skipped). Each version has also been passing seven export-contract tests and 15 installed-wheel transport tests. Ruff, type checking, the wheel without the optional extra, and 476 differential conversion cases have been passing.
The API-resource suite and the fine-tuning positional-argument integration module have not been running locally. The official Steady server has been missing a pinned dependency from its cache, and its registry has been unreachable. CI coverage for those tests remains important.
The new tests have been covering first use, missing and broken optional installations, a preloaded module without an import spec, public class identity, aliases, scalar subclasses and nested conversions. A broken optional installation can select a different private implementation class before construction. The public client still raises the missing-extra error when constructed. The vendored package export now loads the original transport class on demand.
All 83 comparisons with both Python changes and Codex off
Each row reports a median in milliseconds. The paired percentage uses within-pair ratios, so it can differ from the ratio of the displayed medians. When a row has 64 pairs, the table uses the independent confirmation. The two SQLite rows have been writing 2 items of 256 characters and 1,024 items of 4,096 characters. The 32 concurrent ordinary requests and the 32 concurrent streams have separate rows. The short-burst p95 falls outside these medians. The cold_normal and cold_stream rows time the run after imports and fixture setup. The process-launch measurement above includes both.