Avoid redundant whitespace scan in json.loads() for documents without surrounding whitespace
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Decoding a JSON document with json.loads() runs a whitespace-skipping regular expression at the start and end of the document through the pure-Python decode() wrapper, on every call, before and after the C scanner does the actual parsing. The overwhelming majority of documents have no leading or trailing whitespace, so both matches scan zero characters yet still pay for the call and the match-object allocation. For the small documents that dominate real traffic, that fixed overhead is a meaningful fraction of the total decode time.
Skipping the leading match when the document does not begin with whitespace, and the trailing match when the parse already consumed the whole string, removes that overhead from the common case. On a tiny document it is roughly 1.5x faster; documents that do have surrounding whitespace keep the original behavior, and large documents are unaffected.
This overlaps with the broader rewrite proposed in gh-117397; it is filed separately so the small, self-contained version can be evaluated on its own.
Linked PRs
- gh-150861
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza por json.loads() y su wrapper decode() de Python puro; después compara el manejo de los espacios en blanco con el escáner de C descrito en el issue y con la reescritura más amplia de gh-117397. Se considera terminado cuando los documentos sin espacios en blanco circundantes evitan los escaneos redundantes, mientras que los documentos con espacios en blanco conservan su comportamiento; gh-150861 indica que el trabajo ya está en curso.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- performance
- Tipo de issue
- Refactorización
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100