Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-56423

Explore CPS-like approach in SBE VM and BSON parser

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 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

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            nikita.lapkov@mongodb.com Nikita Lapkov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated: