Speed up the type keyword (commit ready)

Đang mở
#1,605 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 6 ngày

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

Đánh giá

Issue này chưa được đánh giá.

Mô tả

type in _keywords.py calls any() on a generator expression. A loop that returns at the first type that matches is faster. The checks, their order, and the error message do not change.

Benchmark (Draft202012Validator) Before After Change
{"type": "integer"} with 5 532 ns 411 ns -22.7%
An object with 7 properties that have a type 24.5 µs 22.5 µs -8.2%
An array of 1000 numbers 1.96 ms 1.81 ms -7.8%

I measured no slowdown on 29 inputs (Apple M5, CPython 3.14.6). The test suite, ruff, and mypy pass. Old and new results matched on the JSON-Schema-Test-Suite and on 1M random inputs.

New contributors cannot open pull requests here now. The commit is https://github.com/g4lb/jsonschema/commit/32b8ee8029af3764dc2ed294a527f1495a67712e. I can open a pull request if you allow it.

Ngôn ngữ chính
Python
Star
5k
Fork
741
Merge trung bình
4 ngày 17 giờ
Pull request đã merge (30 ngày)
6

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 python-jsonschema/jsonschema

Tất cả issue của python-jsonschema/jsonschema

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.