-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Query Execution
A few days ago one of the developers from Google Protobuf team wrote an interesting post on how they achieved 2 GB/s parsing speed, which is almost 2x of previous state of art.
The general idea is to use a chain of tail calls instead of one big while loop with switch statement inside. This forces compiler to optimize most of the tail calls and keep most of arguments on the registers. Wasm3 runtime for WebAssembly uses the same approach.
It could be interesting for us to experiment with this approach in the SBE BSON parser or SBE VM.
Alternatively, we could use computed gotos approach, which is used by Python VM. In this case instead of using switch statement, we can use goto with computed address of label for next instruction.
Protobuf article: https://blog.reverberate.org/2021/04/21/musttail-efficient-interpreters.html
Wasm3 wiki: https://github.com/wasm3/wasm3/blob/main/docs/Interpreter.md#m3-massey-meta-machine
Article about computed goto: https://eli.thegreenplace.net/2012/07/12/computed-goto-for-efficient-dispatch-tables