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.
Hi, I'm the Playwright bot. I compared performance before and after #3373.
#3373 reduces median time for 300 evaluations from 2.92 s to 2.02 s: 31% less time. The returned data matches before and after. With the driver held fixed, the new Python client also takes less time: 21-29% in these measurements.
The optional-validator calls identified in this issue fall from 2,563,300 to zero in a profile of 100 evaluations. This change is on main; it is not yet in a tagged release.
I built both pinned drivers. The old driver is 049226728d2da8054db18b04782a9848b755855e; the new driver is b0e0b7b555e637cc8c0ce94dd98c3be153861333. Both use Node 26.13.1 and headless Chromium 159.0.8154.13, revision 1256.
The runner is macOS 26.7.2 arm64 with Python 3.14.10. The reported macOS 27.2 was not available.
Each process ran 20 warmup evaluations, then three samples of 300 evaluations. I repeated each condition in three processes, changing the order between rounds. The table shows all nine unprofiled samples per condition as their median and minimum. Result assertions were outside the timed loops.
With the new driver fixed, median time falls by 29%; with the old driver fixed, it falls by 21%. This is a shared runner, so absolute timings and percentages vary. The call reduction is deterministic.
The workload was:
js="""Array.from({length: 200}, (_, i) => ({ id: i, name: 'item ' + i, price: i * 1.5, url: 'https://example.com/' + i, tags: ['a', 'b']}))"""# After warmup, with a page from sync_playwright():samples= []
for_inrange(3):
start=time.perf_counter()
for_inrange(300):
result=page.evaluate(js)
samples.append(time.perf_counter() -start)
assertresult==expected# All 200 objects and their fields.
In separate profiles of 100 evaluations, object-validator calls remain at 260,500 and calls to the scalar validators are unchanged. The new schema separates required and optional fields, skips absent options before constructing their paths, and validates present fields directly without the optional wrapper. It still calls is_under_test() per object.
On the merged commit, sync evaluation and handle tests passed: 341 passed, 4 upstream skips. Async evaluation, handle, Python-specific evaluation, and the rolled validator regression passed: 371 passed, 4 upstream skips. Both runs covered Chromium, Firefox, and WebKit in separate pytest processes. Performance measurements were Chromium-only.
The benchmark script, raw samples, profiles, and test logs are in the agent run artifact. No additional fix is proposed: #3373 already contains the change that removes this validation cost.
Triaged on macOS by the Playwright bot - agent run
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
dgozman commentedon Nov 25, 2026
Agent, let's compare performance before and after #3373.
microsoft-playwright-automation commentedon Nov 25, 2026
microsoft-playwright-automation commentedon Nov 25, 2026
Hi, I'm the Playwright bot. I compared performance before and after #3373.
#3373 reduces median time for 300 evaluations from 2.92 s to 2.02 s: 31% less time. The returned data matches before and after. With the driver held fixed, the new Python client also takes less time: 21-29% in these measurements.
The optional-validator calls identified in this issue fall from 2,563,300 to zero in a profile of 100 evaluations. This change is on main; it is not yet in a tagged release.
Comparison, reproduction, and checks
The exact Python commits are:
8b452510884008b70c099a32089d4501c90c721f, the parent of chore: roll Playwright to 1.66.0-next (b0e0b7b555) #3373.f31e7025d36bebc4b55c2e94f97f26ac92e13067, the merged chore: roll Playwright to 1.66.0-next (b0e0b7b555) #3373.I built both pinned drivers. The old driver is
049226728d2da8054db18b04782a9848b755855e; the new driver isb0e0b7b555e637cc8c0ce94dd98c3be153861333. Both use Node 26.13.1 and headless Chromium 159.0.8154.13, revision 1256.The runner is macOS 26.7.2 arm64 with Python 3.14.10. The reported macOS 27.2 was not available.
Each process ran 20 warmup evaluations, then three samples of 300 evaluations. I repeated each condition in three processes, changing the order between rounds. The table shows all nine unprofiled samples per condition as their median and minimum. Result assertions were outside the timed loops.
With the new driver fixed, median time falls by 29%; with the old driver fixed, it falls by 21%. This is a shared runner, so absolute timings and percentages vary. The call reduction is deterministic.
The workload was:
In separate profiles of 100 evaluations, object-validator calls remain at 260,500 and calls to the scalar validators are unchanged. The new schema separates required and optional fields, skips absent options before constructing their paths, and validates present fields directly without the optional wrapper. It still calls
is_under_test()per object.On the merged commit, sync evaluation and handle tests passed: 341 passed, 4 upstream skips. Async evaluation, handle, Python-specific evaluation, and the rolled validator regression passed: 371 passed, 4 upstream skips. Both runs covered Chromium, Firefox, and WebKit in separate pytest processes. Performance measurements were Chromium-only.
Commands:
The benchmark script, raw samples, profiles, and test logs are in the agent run artifact. No additional fix is proposed: #3373 already contains the change that removes this validation cost.
Triaged on macOS by the Playwright bot - agent run