- Notifications
You must be signed in to change notification settings - Fork1k
Parsing gigabytes of JSON per second : used by Facebook/Meta Velox, the Node.js runtime, ClickHouse, WatermelonDB, Apache Doris, Milvus, StarRocks
License
Apache-2.0, MIT licenses found
Licenses found
simdjson/simdjson
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
- Fast: Over 4x faster than commonly used production-grade JSON parsers.
- Record Breaking Features: Minify JSON at 6 GB/s, validate UTF-8 at 13 GB/s, NDJSON at 3.5 GB/s.
- Easy: First-class, easy to use and carefully documented APIs.
- Strict: Full JSON and UTF-8 validation, lossless parsing. Performance with no compromises.
- Automatic: Selects a CPU-tailored parser at runtime. No configuration needed.
- Reliable: From memory allocation to error handling, simdjson's design avoids surprises.
- Peer Reviewed: Our research appears in venues like VLDB Journal, Software: Practice and Experience.
This library is part of theAwesome Modern C++ list.
- Real-world usage
- Quick Start
- Documentation
- Godbolt
- Performance results
- Packages
- Bindings and Ports of simdjson
- About simdjson
- Funding
- Contributing to simdjson
- License
- Node.js
- ClickHouse
- Meta Velox
- Google Pax
- milvus
- QuestDB
- Clang Build Analyzer
- Shopify HeapProfiler
- StarRocks
- Microsoft FishStore
- Intel PCM
- WatermelonDB
- Apache Doris
- Dgraph
- UJRPC
- fastgltf
- vast
- ada-url
- fastgron
- WasmEdge
- RonDB
If you are planning to use simdjson in a product, please work from one of our releases.
The simdjson library is easily consumable with a single .h and .cpp file.
Prerequisites:
g++
(version 7 or better) orclang++
(version 6 or better), and a 64-bitsystem with a command-line shell (e.g., Linux, macOS, freeBSD). We also support programmingenvironments like Visual Studio and Xcode, but different steps are needed. Users of clang++ may need to specify the C++ version (e.g.,c++ -std=c++17
) since clang++ tends to default on C++98.Pullsimdjson.h andsimdjson.cpp into adirectory, along with the sample filetwitter.json. You can download them with the
wget
utility:wget https://raw.githubusercontent.com/simdjson/simdjson/master/singleheader/simdjson.h https://raw.githubusercontent.com/simdjson/simdjson/master/singleheader/simdjson.cpp https://raw.githubusercontent.com/simdjson/simdjson/master/jsonexamples/twitter.json
Create
quickstart.cpp
:
#include<iostream>#include"simdjson.h"usingnamespacesimdjson;intmain(void) { ondemand::parser parser; padded_string json =padded_string::load("twitter.json"); ondemand::document tweets = parser.iterate(json); std::cout <<uint64_t(tweets["search_metadata"]["count"]) <<" results." << std::endl;}
c++ -o quickstart quickstart.cpp simdjson.cpp
./quickstart
100 results.
Usage documentation is available:
- Basics is an overview of how to use simdjson and its APIs.
- Performance shows some more advanced scenarios and how to tune for them.
- Implementation Selection describes runtime CPU detection andhow you can work with it.
- API contains the automatically generated API documentation.
Some users may want to browse code along with the compiled assembly. You want to check out the following lists of examples:
- simdjson examples with errors handled through exceptions
- simdjson examples with errors without exceptions
The simdjson library uses three-quarters less instructions than state-of-the-art parserRapidJSON. To our knowledge, simdjson is the first fully-validating JSON parserto run atgigabytes per second (GB/s) on commodity processors. It can parse millions of JSON documents per second on a single core.
The following figure represents parsing speed in GB/s for parsing various fileson an Intel Skylake processor (3.4 GHz) using the GNU GCC 10 compiler (with the -O3 flag).We compare against the best and fastest C++ libraries on benchmarks that load and process the data.The simdjson library offers full unicode (UTF-8) validation and exactnumber parsing.
The simdjson library offers high speed whether it processes tiny files (e.g., 300 bytes)or larger files (e.g., 3MB). The following plot presents parsingspeed forsynthetic files over various sizes generated with a script on a 3.4 GHz Skylake processor (GNU GCC 9, -O3).
All our experiments are reproducible.
For NDJSON files, we can exceed 3 GB/s withour multithreaded parsing functions.
We distinguish between "bindings" (which just wrap the C++ code) and a port to another programming language (which reimplements everything).
- ZippyJSON: Swift bindings for the simdjson project.
- libpy_simdjson: high-speed Python bindings for simdjson usinglibpy.
- pysimdjson: Python bindings for the simdjson project.
- cysimdjson: high-speed Python bindings for the simdjson project.
- simdjson-rs: Rust port.
- simdjson-rust: Rust wrapper (bindings).
- SimdJsonSharp: C# version for .NET Core (bindings and full port).
- simdjson_nodejs: Node.js bindings for the simdjson project.
- simdjson_php: PHP bindings for the simdjson project.
- simdjson_ruby: Ruby bindings for the simdjson project.
- fast_jsonparser: Ruby bindings for the simdjson project.
- simdjson-go: Go port using Golang assembly.
- rcppsimdjson: R bindings.
- simdjson_erlang: erlang bindings.
- simdjsone: erlang bindings.
- lua-simdjson: lua bindings.
- hermes-json: haskell bindings.
- simdjzon: zig port.
- JSON-Simd: Raku bindings.
- JSON::SIMD: Perl bindings; fully-featured JSON module that uses simdjson for decoding.
- gemmaJSON: Nim JSON parser based on simdjson bindings.
- simdjson-java: Java port.
The simdjson library takes advantage of modern microarchitectures, parallelizing with SIMD vectorinstructions, reducing branch misprediction, and reducing data dependency to take advantage of eachCPU's multiple execution cores.
Our default front-end is called On-Demand, and we wrote a paper about it:
- John Keiser, Daniel Lemire,On-Demand JSON: A Better Way to Parse Documents?, Software: Practice and Experience 54 (6), 2024.
Some peopleenjoy reading the first (2019) simdjson paper: A description of the designand implementation of simdjson is in our research article:
- Geoff Langdale, Daniel Lemire,Parsing Gigabytes of JSON per Second, VLDB Journal 28 (6), 2019.
We have an in-depth paper focused on the UTF-8 validation:
- John Keiser, Daniel Lemire,Validating UTF-8 In Less Than One Instruction Per Byte, Software: Practice & Experience 51 (5), 2021.
We also have an informalblog post providing some background and context.
For the video inclined,
(It was the best voted talk, we're kinda proud of it.)
The work is supported by the Natural Sciences and Engineering Research Council of Canada under grantsRGPIN-2017-03910 and RGPIN-2024-03787.
Head over toCONTRIBUTING.md for information on contributing to simdjson, andHACKING.md for information on source, building, and architecture/design.
This code is made available under theApache License 2.0 as well as under the MIT License. As a user, you can pick the license you prefer.
Under Windows, we build some tools using the windows/dirent_portable.h file (which is outside our library code): it is under the liberal (business-friendly) MIT license.
For compilers that do not supportC++17, we bundle the string-view library which is published under theBoost license. Like the Apache license, the Boost license is a permissive license allowing commercial redistribution.
For efficient number serialization, we bundle Florian Loitsch's implementation of the Grisu2 algorithm for binary to decimal floating-point numbers. The implementation was slightly modified by JSON for Modern C++ library. Both Florian Loitsch's implementation and JSON for Modern C++ are provided under the MIT license.
For runtime dispatching, we use some code from the PyTorch project licensed under 3-clause BSD.
About
Parsing gigabytes of JSON per second : used by Facebook/Meta Velox, the Node.js runtime, ClickHouse, WatermelonDB, Apache Doris, Milvus, StarRocks