You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Regression]: evaluate() with larger results ~40% slower since 1.65 #3362
evaluate() with a medium-sized result got about 40% slower:
importtimefromplaywright.sync_apiimportsync_playwrightJS="Array.from({length: 200}, (_, i) => ({id: i, name: 'item ' + i, price: i * 1.5, url: 'https://example.com/' + i, tags: ['a', 'b']}))"withsync_playwright() asp:
page=p.chromium.launch().new_page()
page.evaluate(JS)
best=1e9for_inrange(3):
start=time.perf_counter()
for_inrange(300):
page.evaluate(JS)
best=min(best, time.perf_counter() -start)
print(f"{best:.2f}s")
Expected behavior
1.64.0: 1.30s
Actual behavior
1.65.2: 1.84s
Additional context
cProfile points at the protocol validator: the t_object validator in protocol/validator_primitives.py is about 60% of the profiled time. For every object node it calls the validator of every key in the schema, and SerializedValue has ~15 optional keys, so most calls are t_optional(None) for keys that aren't there. It also calls context.is_under_test() once per node.
Skipping the call when the key is absent and the validator is a t_optional (the result is None in that case anyway) brings the script above to 1.47s in my test, same output. Validated messages also include every event and initializer, so it's not only evaluate.
Hi, I'm the Playwright bot. I reproduced this and prepared a fix.
Reproduced on 1.65.0, 1.65.2, and current main (de03c865f5738c2291a6a58c8b5c20346d8e70f2) on macOS with Python 3.14. The Python validator calls every absent optional field for each serialized value. The fix skips those calls, while keeping validation of present fields and required fields.
The regression test fails before the fix and passes after it on Chromium, Firefox, and WebKit. It checks the unnecessary calls directly, without a timing threshold.
Reproduction and checks
I evaluated this expression 300 times per sample, taking the best of three samples and checking the returned data:
The runner is macOS 26.7.2 arm64 with Python 3.14.10. The reported macOS 27.2 was not available. All browser checks were headless; published-release benchmarks used Chromium.
Python package
Best time for 300 evaluations
1.64.0
2.710 s
1.65.0
3.399 s
1.65.2
3.155 s
Current main, with fix
2.276 s
A separate comparison used the same client and driver on main, changing only the validator: 3.339 s before the fix and 2.586 s after it (23% less time). In a profile of 100 evaluations, optional-validator calls fell from 2,563,300 to 200,400 (92% fewer calls). Timings vary on this shared runner; the call reduction is deterministic.
The Node.js client benchmark used Node 24.22.3 and the pinned upstream driver (a018f24a4fc76e2120d3b35d2415f1e5bd4b073e), and took 2.162 s. The extra validation cost is in the Python client.
Sync evaluation and handle tests: 329 passed, 4 upstream skips across all three browsers. Async evaluation, handle, Python-specific evaluation, and storage-state tests: 421 passed, 5 upstream skips across all three browsers. No browser-specific validation failure occurred.
An additional comparison checked 800 combinations against the original validator: the results and errors matched for missing required fields, present invalid fields, explicit None values, array nulls, and test hooks.
mypy playwright and scripts/lint.sh passed. Lint used Python 3.13 because the pinned pyright version fails on Python 3.14's standard-library template strings. The benchmark and browser tests used Python 3.14.10.
Activity
microsoft-playwright-automation commentedon Nov 23, 2026
microsoft-playwright-automation commentedon Nov 23, 2026
Hi, I'm the Playwright bot. I reproduced this and prepared a fix.
Reproduced on 1.65.0, 1.65.2, and current main (
de03c865f5738c2291a6a58c8b5c20346d8e70f2) on macOS with Python 3.14. The Python validator calls every absent optional field for each serialized value. The fix skips those calls, while keeping validation of present fields and required fields.The regression test fails before the fix and passes after it on Chromium, Firefox, and WebKit. It checks the unnecessary calls directly, without a timing threshold.
Reproduction and checks
I evaluated this expression 300 times per sample, taking the best of three samples and checking the returned data:
The runner is macOS 26.7.2 arm64 with Python 3.14.10. The reported macOS 27.2 was not available. All browser checks were headless; published-release benchmarks used Chromium.
A separate comparison used the same client and driver on main, changing only the validator: 3.339 s before the fix and 2.586 s after it (23% less time). In a profile of 100 evaluations, optional-validator calls fell from 2,563,300 to 200,400 (92% fewer calls). Timings vary on this shared runner; the call reduction is deterministic.
The Node.js client benchmark used Node 24.22.3 and the pinned upstream driver (
a018f24a4fc76e2120d3b35d2415f1e5bd4b073e), and took 2.162 s. The extra validation cost is in the Python client.Sync evaluation and handle tests: 329 passed, 4 upstream skips across all three browsers. Async evaluation, handle, Python-specific evaluation, and storage-state tests: 421 passed, 5 upstream skips across all three browsers. No browser-specific validation failure occurred.
An additional comparison checked 800 combinations against the original validator: the results and errors matched for missing required fields, present invalid fields, explicit None values, array nulls, and test hooks.
mypy playwrightandscripts/lint.shpassed. Lint used Python 3.13 because the pinned pyright version fails on Python 3.14's standard-library template strings. The benchmark and browser tests used Python 3.14.10.Draft PR: #3368
Triaged on macOS by the Playwright bot - agent run