katydid / katydid/parser-go-json
use simd instructions to make json parser faster
- Dominant language
- Go
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Using SIMD instructions we can speed up the parsing of JSON.
We can do this by implementing a faster drop in replacement of the Scanner interface using SIMD.
```go
type Scanner interface {
Next() (Kind, []byte, error)
Init([]byte)
}
```
For example, we can use SIMD instructions to scan multiple bytes at same time and look ahead to where the end quote of a string is.
This has been done before, see the articles below and tips on [how it has been done before in Go]( https://github.com/lloyd/goj).
We just need it to be adjusted to match our interface and for extra speed (longer lookaheads) make sure we are using the newest AVX512 instructions, which is the next generation of SIMD.
## Articles on parsing JSON with SIMD
* Parsing Gigabytes of JSON per Second - Geoff Langdale and Daniel Lemire - 2019, Springer, The VLDB Journal, Volume 28, Number 6, Pages 941-960
* A blog post explaining how AVX512 can be used to do faster JSON parsing: https://lemire.me/blog/2022/05/25/parsing-json-faster-with-intel-avx-512/
* Filter Before You Parse: Faster Analytics on Raw Data with Sparser - Shoumik Palkar, Firas Abuzaid, Peter Bailis, Matei Zaharia - 2018, VLDB Endowment, Proceedings of the VLDB Endowment, Volume 11, Number 11, Pages 1576-1589
* RE#: High Performance Derivative-Based Regex Matching with Intersection, Complement, and Restricted Lookarounds - Varatalu, Ian Erik and Veanes, Margus and Ernits, Juhan - 2025, ACM New York, NY, USA, Proceedings of the ACM on Programming Languages, Volume 9, POPL, Pages 1 - 32 - Thank you Brink van der Merwe for finding this reference
## Go tips for how to use SIMD in Go
* A fast JSON scanner in go: https://github.com/lloyd/goj - Thank you Cody Ohlsen for finding this reference
* Go supports AVX512 (The next generation of SIMD) instructions: https://tip.golang.org/wiki/AVX512
* A Go optimization story: https://sourcegraph.com/blog/slow-to-simd - Thank you Mikhail Podtserkovskii for finding this reference
* Generate x86 Assembly with Go: https://github.com/mmcloughlin/avo - Thank you Johan Brandhorst-Satzkorn for finding this reference
## Other tips
* Some CPUs have On-demand AVX512 support, which means AVX512 support does not take the first time, see https://github.com/apple/darwin-xnu/blob/0a798f6738bc1db01281fc08ae024145e84df927/osfmk/i386/fpu.c#L176-L201
## Acronyms
* SIMD (single instruction, multiple data)
* SSE (Streaming SIMD Extensions)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.