michalmuskala / jason

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

Use float_to_binary [:short] if available #155

Closed michalmuskala closed 1 year ago

michalmuskala commented 1 year ago

Closes #134

michalmuskala commented 1 year ago

In my simple benchmarks for the float-heavy dataset Canada the runtime goes from 14.87 ms (on par with jiffy) and 33.59 MB memory use, to 7.81 ms (~2x faster than jiffy) and 9.22 MB memory use.

shahryarjb commented 1 year ago

Dear @michalmuskala Can I ask a question of this update?!

I am wondering why you did not write has_short_format in a function? Or inside the float function?

https://github.com/michalmuskala/jason/blob/10f8ef2a0a96287eb821ca21d8ac20f8adc2142c/lib/encode.ex#L130-L147

Thank you

mmmries commented 1 year ago

❤️ 💛 💙 💚 💜 Wohoo! Thanks @michalmuskala

lpil commented 1 year ago

@shahryarjb Because outside of the function it is evaluated once at compile time and as such there is no performance cost to the check.