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

Use rb_cstr2inum to improve performance #103

Closed
wants to merge 1 commit into from

Conversation

evanphx
Copy link
Member

@evanphx evanphx commented Nov 17, 2011

This makes a big difference on Rubinius because it removes having to
create thousands of small Strings and the CAPI handles associated with
those small strings.

This makes a big difference on Rubinius because it removes having to
create thousands of small Strings and the CAPI handles associated with
those small strings.
@chuckremes
Copy link

Please consider this patch. It vastly improves performance on Rubinius and looks like it improves MRI perf slightly too.

@evanphx
Copy link
Member Author

evanphx commented Nov 17, 2011

I thought I'd include a benchmark that shows MRI is also quite a bit faster with this change:

» ruby scratch/cstr_bench.rb 
                user     system      total        real
parse:      6.550000   0.000000   6.550000 (  6.553141)
» gem install json-1.6.1.gem
» ruby scratch/cstr_bench.rb
                user     system      total        real
parse:      2.160000   0.000000   2.160000 (  2.165838)

given the benchmark: https://gist.github.com/1373994

@flori
Copy link
Member

flori commented Nov 28, 2011

Thanks for this suggestion. I have used the fbuffer implementation from the generator in order to use the rb_cstr2inum method. I also used rb_cstr_to_dbl to parse JSON floats which is a bit faster as well. The benchmarking results are below (https://gist.github.com/1399957 for the floats):

Before:

(ffrank@office:json [master] ♢@json ->0)$ ruby -Iext:lib bench.rb 
                 user     system      total        real
parse:       4.260000   0.010000   4.270000 (  4.266780)
(ffrank@office:json ♢@json ->0)$ ruby -Iext:lib bench2.rb 
                 user     system      total        real
parse:      13.270000   0.030000  13.300000 ( 13.302467)

After:

(ffrank@office:json [master] ♢@json ->0)$ ruby -Iext:lib bench.rb 
                 user     system      total        real
parse:       2.550000   0.010000   2.560000 (  2.553988)
(ffrank@office:json [master] ♢@json ->0)$ ruby -Iext:lib bench2.rb 
                 user     system      total        real
parse:      10.530000   0.010000  10.540000 ( 10.546895)

@flori flori closed this Nov 28, 2011
jperkin pushed a commit to TritonDataCenter/pkgsrc-legacy that referenced this pull request Dec 9, 2013
2011-12-01 (1.6.3)
  * Let JSON.load('') return nil as well to make mysql text columns (default to
    '') work better for serialization.
2011-11-21 (1.6.2)
  * Add support for OpenStruct and BigDecimal.
  * Fix bug when parsing nil in quirks_mode.
  * Make JSON.dump and JSON.load methods better cooperate with Rails' serialize
    method. Just use: serialize :value, JSON
  * Fix bug with time serialization concerning nanoseconds. Thanks for the
    patch go to Josh Partlow (jpartlow@github).
  * Improve parsing speed for JSON numbers (integers and floats) in a similar way to
    what Evan Phoenix <[email protected]> suggested in:
    ruby/json#103
2011-09-18 (1.6.1)
  * Using -target 1.5 to force Java bits to compile with 1.5.
jsonn pushed a commit to jsonn/pkgsrc that referenced this pull request Oct 11, 2014
2011-12-01 (1.6.3)
  * Let JSON.load('') return nil as well to make mysql text columns (default to
    '') work better for serialization.
2011-11-21 (1.6.2)
  * Add support for OpenStruct and BigDecimal.
  * Fix bug when parsing nil in quirks_mode.
  * Make JSON.dump and JSON.load methods better cooperate with Rails' serialize
    method. Just use: serialize :value, JSON
  * Fix bug with time serialization concerning nanoseconds. Thanks for the
    patch go to Josh Partlow (jpartlow@github).
  * Improve parsing speed for JSON numbers (integers and floats) in a similar way to
    what Evan Phoenix <[email protected]> suggested in:
    ruby/json#103
2011-09-18 (1.6.1)
  * Using -target 1.5 to force Java bits to compile with 1.5.
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

Successfully merging this pull request may close these issues.

3 participants