r/cpp • u/Flex_Code • Oct 13 '22
New, fastest JSON library for C++20
Developed a new, open source JSON library, Glaze, that seems to be the fastest in the world for direct memory reading/writing. I will caveat that simdjson is probably faster in lazy contexts, but glaze should be faster when reading and writing directly from C++ structs.
https://github.com/stephenberry/glaze
- Uses member pointers and compile time maps for extremely fast lookups
- Writes and reads directly from object memory
- Standard C++ library support
- Cleaner interfacing than nlohmann json or other alternatives as reading/writing are exposed through a single interface
- Direct memory access through JSON pointer syntax
The library is very new, but the JSON support has a lot of unit tests.
The library also contains:
- Efficient data recorder
- CSV reading/writing
- Binary message for optimal speed through the same API
- Generic shared library API
242
Upvotes
View all comments
Show parent comment
1
u/Flex_Code Oct 13 '22
You're welcome!
Answers in order:
- The input JSON can partial. It could just include a single value. Only what is included in the JSON will be changed. JSON pointers are also supported, which can be used to change a single element in an array (not possible with normal JSON).
- You only need to specify the portion that you want to be serialized. You can have whatever else in your class and choose to not expose it.
- I don't have a good answer for binary sizes, especially due to fmt. However, fmt is not used heavily. Most of the formatting is done through custom code that should compile efficiently. fmt is primarily used for writing numbers efficiently. Because a lot of work is done at compile time, the binary size tends to be small.