“It's worth looking at if you're into this sort of thing.”
Parsing Gigabytes of JSON per Second
simdjson:用 SIMD 指令让单核每秒解析数 GB 的 JSON
JSON 是网络上无处不在的数据交换格式,数据量大时解析会成为性能瓶颈。作者表明,即使这个问题已相当成熟,仍能大幅提速:提出首个符合标准、在商用处理器单核上每秒处理数 GB 数据的 JSON 解析器,所用指令数可低至 RapidJSON 等先进参考解析器的四分之一或更少。与其他验证型解析器不同,其软件 simdjson 大量使用单指令多数据(SIMD)指令,并以宽松许可证开源以保证可复现。
HN 上的人称这篇论文写得非常好、例子丰富,把它作为用 SIMD 加速解析的代表,很多后来的项目都借鉴了其中的技术。
学习路径
读这篇之前,按顺序读书架上的 2 篇 · 参考文献来自 OpenAlex,顺序和要点由 Claude Code 排出候选里与 simdjson 直接相关的只有两篇:同一作者关于利用 SIMD 与特殊指令加速字节处理的工作,用来熟悉指令级并行的思路。
- 1
同一作者用 AVX2 做 Base64 编解码,展示用 SIMD 批量处理字节的基本手法。
读如何用向量指令一次处理多个字节与查表替代分支。
- 2
展示无进位乘法(CLMUL)指令的使用,simdjson 也用类似指令处理引号区域位掩码。
读CLMUL 指令的作用;只看它如何把位运算映射到硬件指令。
- 3Parsing Gigabytes of JSON per Second
目标论文:用 SIMD 先做结构字符与字符串边界的分类,再构建解析,让单核达到每秒数 GB。
读两阶段设计(先找结构字符、再解析)、减少分支的技巧、UTF-8 校验与数字解析。
HN 书评
推荐在前,同类按时间 · 每篇最多保留 20 条,统计用全部提及“the simdjson paper uses similar techniques, is extremely well-written and has great examples.”
“He's probably tired of copy-pasting the specs of his reference hardware (Skylake Parsing Gigabytes of JSON per Second)”
“Some real-world examples in simdjson: Parsing Gigabytes of JSON per Second”
“Other names to look out for are the previously aforementioned Wojciech Muła, as well as Daniel Lemire (of simdjson [4][5]).”
“Under the hood, it borrows a lot from this paper on using simd for json parsing: Parsing Gigabytes of JSON per Second”
- Parsing Gigabytes of JSON per Second [pdf] ↗rickdeveloper · 2020-05-05 · 2 分
- Parsing gigabytes of JSON per second ↗signa11 · 2021-10-21 · 139 分
- Parsing Gigabytes of JSON per Second ↗ibobev · 2024-09-11 · 5 分