Skip to content

Two Stage JSON Tape Decode #3629

Open
Open

Description

@tustvold

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 to implement a fast vectorised lookup table
  2. Uses clmulq 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

Activity

  1. self-assigned this
    on Jan 29, 2023
  2. removed their assignment
    on Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions