jiffy
jiffy copied to clipboard
Optimize encoding performance in Erlang
Right now jiffy requires keys in maps or keyword tuples to be strings to be successfully encoded.
If existing keys in map are integers - whole map should be recreated with keys converted to integers - which is huge overhead in terms of CPU/RAM usage.
This patch allows integer to be serialized into JSON as map's key as well.
May be it should be enabled only when some option is passed to encoder.
@davisp ping :) would you consider including this optimization?
Idea is to avoid expensive operation of changing
%{
1 => "val",
2 => "val"
}
to
%{
"1" => "val",
"2" => "val"
}
before passing it to jiffy encoder.
:smiling_imp: Bad excuse is that JS JSON.stringify allows it :) :P :P
If yes - I'll rebase it on current master and also update docs.
Python allows it as well so I'm not against it.
Ok, did small fixes.
Do you want another branch + everything squashed in one commit?
Just tried this and for me it fails for jiffy:encode(#{2 => 2, 1 => 1}).
** exception throw: {error,{invalid_object_member_key,1}} in function jiffy:encode/2 (/Users/mikael/work/infranet-erl/_build/default/lib/jiffy/src/jiffy.erl, line 99)
jiffy:encode(#{2 => 2, 1 => 1}).
I'm not sure you are using version from this branch. I think it is not merged yet into main tree :(
Would be nice to merge this