Hacker News new | ask | show | jobs
by peterohler 527 days ago
I missed responding to your assertion that the Oj::Parser was not thread safe. An individual Oj::Parser instance is not thread safe just like other Ruby object such as a Hash but multiple Oj::Parser instances can be created in as many threads as desired. The reason each individual Oj::Parser is not thread safe is that it stores the parser state.
1 comments

Yes that's what I meant. The benchmark suite I took from rapidjson was benchmarking against:

    Oj::Parser.usual.parse(string)
That is what isn't thread safe. And yes you can implement a parser pool, or simply so something like:

   parser = (Thread.current[:my_parser] ||= Oj::Parser.new(:usual))
But that didn't really feel right for a benchmark suite, because of the many different ways you could implement that in a real world app. So it's unclear what the real world overhead would be to make this API usable in a given application.

> is that it stores the parser state.

And also a bunch of parsing caches, which makes it perform very well when parsing the same document over and over, or documents with a similar structure, but not as well when parsing many different documents. But I'll touch on that in a future post when I start talking about the parsing side.