[Regression]: evaluate() with larger results ~40% slower since 1.65

Đang mở
#3,362 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
62/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
performance

Hướng nghiên cứu

Start in protocol/validator_primitives.py, reading t_object and the t_optional helper, and trace where SerializedValue's schema keys are iterated. Before editing, run the issue's page.evaluate benchmark script to record a baseline, then re-run it after skipping the optional-key validators when a key is absent. Also run the protocol validator tests in tests/ (the suite that round-trips validated messages) to confirm malformed messages are still rejected. Done means the benchmark is back near 1.30s with unchanged validation behaviour, including for events and initializers.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Last Good Version

1.64.0

First Bad Version

1.65.0

Steps to reproduce

evaluate() with a medium-sized result got about 40% slower:

import time
from playwright.sync_api import sync_playwright

JS = "Array.from({length: 200}, (_, i) => ({id: i, name: 'item ' + i, price: i * 1.5, url: 'https://example.com/' + i, tags: ['a', 'b']}))"

with sync_playwright() as p:
    page = p.chromium.launch().new_page()
    page.evaluate(JS)
    best = 1e9
    for _ in range(3):
        start = time.perf_counter()
        for _ in range(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.

Environment
- Operating System: macOS 27.2
- CPU: arm64
- Browser: Chromium
- Python Version: 3.14
- Other info:
Ngôn ngữ chính
Python
Star
15.1k
Fork
1.3k
Merge trung bình
6 giờ 16 phút
Pull request đã merge (30 ngày)
53

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của microsoft/playwright-python

Tất cả issue của microsoft/playwright-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.