michalmuskala / jason

A blazing fast JSON parser and generator in pure Elixir.
Other
1.62k stars 169 forks source link

Add strict opts on decode #87

Closed soteras closed 4 years ago

soteras commented 5 years ago

86

I've refactor Decode module, because when I tried to add new opt is was very difficult because all functions add key_decode, string_decode and I would have to refactor all functions, now It's ease to add new options.

I added strict option on decode because I need to know when my JSON has duplicated keys.

iex(3)> Jason.decode!(~s({"a": 1, "a": 2}), maps: :strict)
** (Jason.DecodeError) duplicate key: a
    (jason) lib/jason.ex:84: Jason.decode!/2
michalmuskala commented 5 years ago

Unfortunately, I'm afraid that extracting the options and allocating the funs on each element is going to kill the performance completely. In this library in particular performance is far more important than ease of maintenance. That said, I haven't actually benchmarked it, it might be fine - loosing 1 to 2% would be ok, anything more is probably prohibitive.

soteras commented 5 years ago

Is there a way to benchmarked it?

michalmuskala commented 5 years ago

There are benchmarks in the bench folder with some instructions in the README.

I run some trimmed down version of the full benchmark and right now it seems that on object-heavy JSON this PR is about 4-7% slower than current master without strict decoding.

michalmuskala commented 4 years ago

Given no changes in status of this PR for over a year, I'm going to close it. If there's a desire to pick up the work again, please re-open this with the required changes & benchmark data.