Parser performance JSON vs Nix

Does anyone have insights on the parsers’ performance for reading large attrsets from JSON vs Nix expressions?

For example if I need to serialize a large Nix expression ( all primitives ) am I shooting myself in the foot writing a Nix file vs JSON?

Aside from the PITA of writing a serializer in Nix ( not really that bad, but toJSON is just sitting here ); I was honestly doing it under the assumption that it was going to be faster than JSON → Nix.

I can benchmark but thought I’d poke my head in to see if anyone had already tested this.

For context Im reading/writing large lockfile type data with ~100,000 string and boolean attrs.


Maybe @joepie91 knows? :slight_smile:

1 Like

In my experience, JSON is faster than Nix. Most likely because the parser is simpler.
I wrote a little benchmark, and the difference at least for simple structures is rather small, (JSON is about 1.5x faster)

1 Like


Thank you. Makes total sense. JSON parsing is dead simple while Nix has a much more complex parser and lexer, even if you aren’t “using” most of the features.

I appreciate you reporting back on this.

Nix’s import would be two-step here: first making AST (tree of Expr*) and then evaluate it to data types (tree of Value*).

While JSON has no functions, variables, applications, … and thus can be loaded in one-step