Idea: apply the & ~v once in the SWAR scans that let non-ASCII bytes through
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 55/100
- Tipo de issue
- Refactorización
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- cpp
- Área
- backend, performance
Línea de trabajo
Read find_string_delimiter() in include/nlohmann/detail/input/string_scan.hpp and the SWAR tail of plain_output_run() in include/nlohmann/detail/view/serializer.hpp. First compare the old and proposed masks with GCC and Clang generated code, then run the issue's random-word and adjacent-byte checks and the existing test suite with JSON_USE_SIMDUTF and JSON_NO_SIMD. Done means the masks match bit for bit and the change shows a worthwhile instruction reduction.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Idea
#6033 drops the & ~x from the 8-byte (SWAR) tests for special bytes in strings, wherever bytes from 0x80 are stops anyway. Two SWAR scans let bytes from 0x80 through, so they still need the & ~x. Each of them still applies it three times:
find_string_delimiter()ininclude/nlohmann/detail/input/string_scan.hpp(only withJSON_USE_SIMDUTFand C++17), which hands non-ASCII runs to simdutf;- the SWAR tail of
plain_output_run()ininclude/nlohmann/detail/view/serializer.hpp, which handles the last 8–15 bytes after the SSE2 loop, or the whole string without SIMD.
const std::uint64_t hit = ((q - ones) & ~q & high)
| ((b - ones) & ~b & high)
| ((v - 0x2020202020202020ull) & ~v & high);
The bytes '"' (0x22) and '\\' (0x5C) have no top bit, so the top bits of ~q and ~b are the same as those of ~v. The three masks can therefore be applied once:
const std::uint64_t hit = ((q - ones) | (b - ones) | (v - 0x2020202020202020ull)) & ~v & high;
The result is the same bit for bit, not only the same lowest flagged byte, so the comments about borrows stay true. It saves two ANDs per 8 bytes.
Expected gain
Small and not measured. find_string_delimiter() is the main loop of the simdutf string path, while the plain_output_run() tail runs at most once per string on SIMD builds. As with #6033, Clang may already find this reduction itself and GCC may not, so any gain would show up with GCC first. Checking the generated code (instruction count per word with GCC and Clang) would show whether it is worth a PR.
Tests
A check like the one in #6033, comparing the old and the new mask for random words and for every pair of adjacent byte values (compiled with GCC -O1, since Clang folds the two expressions into one), plus the existing test suite with JSON_USE_SIMDUTF and with JSON_NO_SIMD.
Breaking changes
None. Only the bodies of internal functions would change.
🤖 Generated with Claude Code
- Lenguaje dominante
- C++
- Estrellas
- 50.9k
- Forks
- 7.5k
- Merge medio
- 1 d 3 h
- PR fusionados (30 d)
- 217
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la 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.
Más de nlohmann/json
-
documentation kind: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
kind: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
kind: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
kind: bug performance
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
dump(): the recursive frame grew from 480 to 2304 bytes in unoptimized builds, so 128 levels need 288 KiB of stackPosiblemente ocupada @nlohmann la tomó hoy. Abiertokind: enhancement/improvement
nlohmann/json#6116 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de nlohmann/json
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
bazel-contrib/rules_go#4784 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
TUIs: Fix TUI CMakesAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
RMIT-Rover-Team/equinox-2#145 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
eunomia-bpf/bpftime#779 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 79/100
Los mantenedores suelen responder en 1 día