As a weekend project, I created JsnPrsr, a
fast, small and lightweight JSON parser (and serializer),
written in Java, with no external dependencies. I played around with
Caliper to microbenchmark different
snippets of code to squeeze some more performance out of it, within bounds of
keeping the code readable.
Running some artificial performance benchmarks against
the json.org reference implementation and
another fast and minimal JSON parser, resulted in the following timings:
Unsurprisingly, the json.org implementation is slower than the others.
JsnPrsr is a tiny bit faster on parsing than minimal-json, but is slower on serializing in some cases.
One of the reasons for slower serialization is that minimal-json stores numbers
as strings, which means significantly faster serialization, but also a
significant memory overhead (e.g. it couldn’t parse a
181 megabyte JSON file, because it ran out of memory).
Changing JsnPrsr to also store numbers as strings is straightforward, and would probably even improve
parsing. Another difference which contributes to minimal-json’s memory overhead is that it uses more elaborate
datastructures for storing JSON in, whereas JsnPrsr uses the minimal datastructures required to work
with them (but can easily be adapted to use other datastructures).
When trying it out on a more realistic example (a list of Twitter statuses), the differences
become even smaller:
Overall, JsnPrsr is a little bit faster than minimal-json, but not really worth mentioning.