Two Stage JSON Tape Decode
- Dominant language
- Rust
- Stars
- 3.6k
- Forks
- 1.3k
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 169
Description
**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
The TapeDecoder added in #3479 is fairly naive, in that it performs a scan of the input stream and uses the encountered bytes to directly drive its state machine. Broadly speaking this leads to an unpredictable branch on every input byte. This is not ideal, and severely limits throughput.
**Describe the solution you'd like**
https://arxiv.org/pdf/1902.08318.pdf describes a two stage approach, as used by simdjson, to efficiently compute the structural indices ahead of time. That is the start and end positions of all atoms, objects and arrays. This allows the parsing state machine to very efficiently produce the parsed tape.
We should do something similar, unfortunately the approach as described in the paper relies on two tricks:
1. Uses [pshufb](https://www.felixcloutier.com/x86/pshufb) to implement a fast vectorised lookup table
2. Uses [clmulq](https://www.felixcloutier.com/x86/pclmulqdq) to implement fast "quote mask filling"
Fortunately both of these have stable intrinsics in `std::arch` that we can use, although this will require some target-feature shenanigans.
**Describe alternatives you've considered**
**Additional context**
Contributor guide
Research direction
Start by locating the TapeDecoder introduced in #3479 and reviewing the referenced two-stage simdjson paper. Completion would be a two-stage structural-index approach that produces the parsed tape using the cited std::arch intrinsics, with target-feature handling addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- performance
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100