Skip to content

v3.0.0

Choose a tag to compare

@Mosaad-M Mosaad-M released this 03 Oct 15:02
· 9 commits to master since this release
21d8d12

Parsed documents now use a flat layout, as yyjson does: one contiguous block of 16-byte values plus a string arena. Parsing is up to 3.9× faster and uses up to 10× less memory, and the library no longer recurses anywhere. Breaking API change; read-only 2.x code compiles unchanged.

Highlights

  • parse_json returns a read-only JsonDoc. Lookups (doc["k"], doc[0]) return JsonRef views instead of deep copies. The compiler keeps the document alive while a view is in use.
  • New:
    • items() and entries() for iteration;
    • as_string_slice() for zero-copy strings;
    • to_value() for a mutable JsonValue copy.
  • Faster parsing than 2.0.0: mixed documents 3.9× faster (62.6 → 15.9 ms); integers and floats 1.1–1.3×. Serialization is on par or faster.
  • Less memory: parsing adds at most about 8× the input size in the worst case ([0,0,…]), down from 85×, and about 3× for typical documents.
  • No recursion anywhere: parsing, serialization, copy, conversion and destruction are all iterative, for parsed documents and built trees alike. A 1M-deep built tree works; 2.0 crashed at about 10k.
  • No hash flooding: parsed objects use a sorted key index; built objects hash keys with a random seed per object.

Migrating from 2.x

  • Mutating a parsed document: var v = parse_json(s).to_value(), then v.set(...) / v.append(...).
  • Keeping a value after its document is gone: use to_value(). The compiler rejects views that would outlive their document.
  • Functions that took a parsed JsonValue can take JsonRef[_] or JsonDoc instead.

See CHANGELOG.md for details and benchmarks.