Speed up the type keyword (commit ready)

Abierto
#1,605 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 6 días

Nadie ha tomado este issue todavía.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

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.

Lenguaje dominante
Python
Estrellas
5k
Forks
741
Merge medio
4 d 17 h
PR fusionados (30 d)
6

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-jsonschema/jsonschema

Todos los issues de python-jsonschema/jsonschema

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.