jsonm icon indicating copy to clipboard operation
jsonm copied to clipboard

Performance differences vs yojson

Open yminsky opened this issue 8 years ago • 7 comments

For a number of reasons, I'd prefer to use jsonm rather than yojson, but yojson is considerably faster. We noticed this in some internal benchmarks, which tracked pretty closely what came up in this blog post:

http://rgrinberg.com/posts/ocaml-json-benchmark/

According to that post, it takes about 2x the time, and allocates maybe 25x as much.

Is there any appetite for working performance of jsonm?

yminsky avatar Nov 26 '17 17:11 yminsky

AFAIR yojson doesn't check encoding validity so I guess jsonm is bound to be slower.

Regarding allocation that's a bit surprising but I suppose is due to the internal continuation based monkey dance for supporting non-blocking scenarios. I'd gladly rewrite all this in direct style along these lines once we have effects in the language...

But before that actually happens maybe a little bit of profiling might uncover some stupid pattern in the implementation.

dbuenzli avatar Nov 26 '17 17:11 dbuenzli

Also note sure exactly what your "reasons" are but jsonm is quite precise with location tracking for error reporting. If you don't really care about that maybe @seliopou's angstrom based json decoder is worth considering.

dbuenzli avatar Nov 26 '17 18:11 dbuenzli

That's an interesting idea. I'll check with @seliopou.

y

On Sun, Nov 26, 2017 at 1:17 PM, Daniel Bünzli [email protected] wrote:

Also note sure exactly what your "reasons" are but jsonm is quite precise with location tracking for error reporting. If you don't really care about that maybe @seliopou https://github.com/seliopou's angstrom based json https://github.com/inhabitedtype/angstrom/blob/master/examples/rFC7159.ml decoder may be worth considering.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/dbuenzli/jsonm/issues/10#issuecomment-347027681, or mute the thread https://github.com/notifications/unsubscribe-auth/AArqJq8v8hrDaMz-OlhUXA3Q8LCuwpkSks5s6atBgaJpZM4Qq2he .

yminsky avatar Nov 26 '17 22:11 yminsky

Cool, if you end up benchmarking that aswell against jsonm I'm interested in hearing the results.

dbuenzli avatar Nov 27 '17 16:11 dbuenzli

I'm curious, @yminsky have you tried writing parsers using angstrom in the end?

I was considering different parsers (including jsonm) and found this issue. We'd be interested in avoiding allocation of the json AST for performance reasons at Cryptosense as well so angstrom could prove useful for that.

The idea in the end would be to write a ppx to derive such json parsers/printers.

NathanReb avatar Nov 15 '18 14:11 NathanReb

@seliopou wrote such a parser, though we haven't open sourced it yet. He can say more, and I think we'd be happy to release it.

yminsky avatar Nov 16 '18 01:11 yminsky

Those parsers have actually always been open source. The original version is in the angstrom repository here. Earlier this year I tweaked it a bit and put it into a separate repository called jsonaf. It however has yet to seen an OPAM release.

seliopou avatar Nov 17 '18 16:11 seliopou