Idea: apply the & ~v once in the SWAR scans that let non-ASCII bytes through
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 55/100
- Tipo di issue
- Refactoring
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- cpp
- Ambito
- backend, performance
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- C++
- Stelle
- 50.9k
- Fork
- 7.5k
- Merge medio
- 1g 3h
- PR unite (30g)
- 217
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nlohmann/json
-
documentation kind: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
kind: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
kind: bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
kind: bug performance
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
dump(): the recursive frame grew from 480 to 2304 bytes in unoptimized builds, so 128 levels need 288 KiB of stackForse già presa @nlohmann l’ha presa oggi. Apertakind: enhancement/improvement
nlohmann/json#6116 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di nlohmann/json
Issue simili
-
Favicons are coolApertaenhancement frontend
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
Spot Capacity Round Trips tests accept the two largest rising runsForse già presa Una pull request collegata a questa issue è aperta o già unita. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
intel/torch-xpu-ops#6197 ·
I maintainer di solito rispondono entro 1 giorno
-
project: hipblaslt
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
ROCm/rocm-libraries#15746 ·
I maintainer di solito rispondono entro 2 giorni
-
Needs: Triage :mag:
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
react/react-native#60000 ·
I maintainer di solito rispondono entro 2 giorni