json
json copied to clipboard
Make JSON::Parser initialization faster
Remove calls to rb_funcall, don't go back in to interpreter if not necessary. Also remove unnecessary calls to rb_respond_to(val) when val is nil. Speedup of JSON.parse when parsing small amount of data in a tight loop is up to 40%.
Here's the benchmark code: https://gist.github.com/luke-gru/adf7468fbc0a3807b5f9a875fcfce116
On my machine:
Rehearsal ----------------------------------------------
json parse (old) 4.140547 0.001651 4.142198 ( 4.262071)
------------------------------------- total: 4.142198sec
user system total real
json parse (old) 4.099210 0.011923 4.111133 ( 4.246992)
Rehearsal ----------------------------------------------
json parse (new) 3.163645 0.003476 3.167121 ( 3.290742)
------------------------------------- total: 3.167121sec
user system total real
json parse (new) 3.121472 0.004022 3.125494 ( 3.198764)
Speedup of JSON.parse when parsing small amount of data in a tight loop is up to 40%.
:open_mouth:
@luke-gru Can you keep the current indent style? We can view only code changes with https://github.com/flori/json/pull/512/files?w=1. But style changes may causes code-conflict when I backport this to ruby/ruby.
HI @hsbt, for the JSON init function, it's a bit subtle but I had to remove the check if (!NIL_P(opts)) and move it below where I could assure that opts was a Hash, so I could use RHASH_SIZE() on it. So for that function it's not just a style change. For parser.c, I think I used a different version of ragel and all the whitespace changed. I could fix this, do you want me to look into it?
EDIT: my ragel is Ragel State Machine Compiler version 6.10 March 2017
So for that function it's not just a style change.
I know that. I say parser.rl and parser.h. I hope you make your change is only https://github.com/flori/json/pull/512/files?w=1, not https://github.com/flori/json/pull/512/files.
Understood, sorry for the confusion. Just updated it.
I accept this proposal. But I'm not familiar with C internals. I requested additional review for @nobu
@luke-gru @hsbt @nobu any ETA on this being released?
Yeah, I'll try to get this updated some time today. Thanks for the reminder 😄
I finally got around to working on this. I added a 2nd commit so you can see the changes from the first. When approved, I will squash them.
@luke-gru @hsbt @nobu any ETA on this being released? :D (it's more than a year from the last time I asked so hope you don't mind)