simdjson
3.11.0
Ridiculously Fast JSON
|
The simdjson library takes advantage of SIMD instruction sets such as NEON, SSE and AVX to achieve much of its speed. Because these instruction sets work differently, simdjson has to compile a different version of the JSON parser for different CPU architectures, often with different algorithms to take better advantage of a given CPU!
The current implementations are:
In many cases, you don't know where your compiled binary is going to run, so simdjson automatically compiles all the implementations into the executable. On Intel, it will include 4 implementations (icelake, haswell, westmere and fallback), on 64-bit ARM it will include just one since running dispatching is unnecessary, and on PPC it will include 2 (ppc64 and fallback).
If you know more about where you're going to run and want to save the space, you can disable any of these implementations at compile time with -DSIMDJSON_IMPLEMENTATION_X=0
(where X is ICELAKE, HASWELL, WESTMERE, ARM64, PPC64, LSX, LASX and FALLBACK).
The simdjson library automatically sets header flags for each implementation as it compiles; there is no need to set architecture-specific flags yourself (e.g., -mavx2
, /AVX2
or -march=haswell
), and it may even break runtime dispatch and your binaries will fail to run on older processors. Note: for POWER9 processors make sure you compile it with -mcpu=power9
and -mtune=power9
to get maximum performance.
When you first use simdjson, it will detect the CPU you're running on, and swap over to the fastest implementation for it. This is a small, one-time cost and for many people will be paid the first time they call parse()
or load()
.
You can check what implementation is running with active_implementation
:
Implementation detection will happen in this case when you first call name()
.
You can list all available implementations, regardless of which one was selected:
And look them up by name:
When an implementation is not available, the bracket call simdjson::get_available_implementations()[name]
will return the null pointer.
The available implementations have been compiled but may not necessarily be run safely on your system see Checking that an Implementation can Run on your System.
If you're trying to do performance tests or see how different implementations of simdjson run, you can select the CPU architecture yourself:
You are responsible for ensuring that the requirements of the selected implementation match your current system. Furthermore, you should check that the implementation is available before setting it to simdjson::get_active_implementation()
by comparing it with the null pointer.
You should call supported_by_runtime_system()
to compare the processor's features with the need of the implementation.
The call to supported_by_runtime_system()
may be relatively expensive. Do not call supported_by_runtime_system()
each time you parse a JSON input (for example). It is meant to be called a handful of times at most in the life of a program.