Speed up the type keyword (commit ready)

Aberta
#1,605 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 6 dias

Ninguém assumiu esta issue ainda.

Avaliação

Esta issue ainda não foi avaliada.

Descrição

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.

Linguagem predominante
Python
Estrelas
5k
Forks
741
Merge médio
4d 17h
PRs com merge (30d)
6

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de python-jsonschema/jsonschema

Todas as issues de python-jsonschema/jsonschema

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.