Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: tradeoffs? #12

Open
chenglou opened this issue Oct 5, 2017 · 1 comment
Open

Question: tradeoffs? #12

chenglou opened this issue Oct 5, 2017 · 1 comment

Comments

@chenglou
Copy link

chenglou commented Oct 5, 2017

Hello @johnwright. This JSON library looks interesting! I'll read its paper, but I was wondering about its tradeoffs too (perf, size, theoretical blockers, etc.)?

The idea of having a free decoder from an encoder or vice-versa sounds pretty attractive, and if possible, I'd like the official Reason one to be free of ppx (which is needed mostly because of the usual encoding/decoding boilerplate).

@johnwright
Copy link
Member

Hi @chenglou, in terms of tradeoffs it's worth me saying that this library isn't exactly one-to-one with the original pickler combinators paper, e.g. the conventional decoder input is a stream of bytes, but in this case it's a Js.Json.t.

I'd say the perf tradeoff is safety vs. allocations, decoding creates a lot of Js.Result.ts and maps/binds them, which is more expensive than an unsafe approach. There are some interesting opportunities for optimisation though, structure-sharing can reduce memory footprint.

I'm not really aware of any theoretical issues, but here's one consideration that comes up in practice: If you're used to parser combinators, you can expect extreme flexibility in constructing decoders. With a pickler combinator approach, you have to ensure that everything is reversible, and so provide functions in both directions. If you're only interested in decoding something very complex, having to provide two functions for things can be a drag.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants