I wrote a fast C json parser a few years ago (+600megs/s) And it was an interesting experience. Validating the json roughly halved the performance. The most interesting performance gain was going from using aligned structs to packed byte offsets being accessed using memcpy. It added 20-30%. The overhead of aligning was nothing compared to fewer cache misses. In the end i found that making a truly fast json parser mostly depend on what you parse it to. Like, is the structure read only, and how fast is it to access?
There is a nugget buried at the bottom of this: you will get different output for different kinds of for ... range or for i ... loops. You'd think these are equivalent:<p><pre><code> for i = range arr {
sum += arr[i]
}
for _, c = range arr {
sum += c
}
</code></pre>
... but the latter is 4 bytes shorter in x86. The compiler takes things literally.
> Both the Ruby Oj and the C parser OjC are the best performers in their respective languages.<p>Um, no, they arent:<p><a href="https://github.com/simdjson/simdjson" rel="nofollow">https://github.com/simdjson/simdjson</a>
How does this compare to something like <a href="https://github.com/valyala/fastjson" rel="nofollow">https://github.com/valyala/fastjson</a> ?
I wonder how people that make super specific things like this their whole career make money. I wonder if they are independently wealthy and just do things like this for fun