Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Learning from performance improvements on Graph...

Learning from performance improvements on GraphQL Ruby

https://www.meetup.com/graphql-tokyo/events/295606838/

Meetup #21 Guest talk and lightning talks

Fumiaki MATSUSHIMA

September 13, 2023
Tweet

More Decks by Fumiaki MATSUSHIMA

Other Decks in Technology

Transcript

  1. Summary of my last talk - GraphQL Ruby 2.0.13 (the

    latest version at that time) is twice slower than 1.5.15
  2. Benchmark target type Article { field0: String! field1: String! ...

    fieldN: String! } type Query { articles: [Article!]! } query { articles { field0, field1, ..., fieldN } }
  3. Benchmark target type Article { field0: String! field1: String! ...

    fieldN: String! } type Query { articles: [Article!]! } query { articles { field0, field1, ..., fieldN } } Num of articles = 1000 Num of fields = 100
  4. Benchmark env - GitHub Actions (ubuntu-latest) - Ruby 3.2.2 -

    https://github.com/mtsmfm/graphql-ruby-benchmark
  5. Benchmark target type Article { field0: String! field1: String! ...

    fieldN: String! } type Query { articles: [Article!]! } query { articles { field0, field1, ..., fieldN } } Num of articles = 1000 Num of fields = 100
  6. Benchmark target type Article { field0: String! field1: String! ...

    fieldN: String! } type Query { articles: [Article!]! } query { articles { field0, field1, ..., fieldN } } Num of articles = 1000 Num of fields = 100 = 100,000 fields!
  7. Learning from PR #4399 1. Field related code can be

    a hotspot a. Even context lookup
  8. require 'bundler/inline' gemfile do source 'https://rubygems.org' gem 'benchmark-ips', require: 'benchmark/ips'

    gem 'graphql' end state = GraphQL::Execution::Interpreter::Runtime::CurrentState.new Benchmark.ips do |x| x.report('send') do state.public_send(:current_arguments) end x.report('direct') do state.current_arguments end x.compare! end
  9. public_send is 2 times slower $ ruby foo.rb Warming up

    -------------------------------------- send 889.676k i/100ms direct 2.157M i/100ms Calculating ------------------------------------- send 8.757M (± 7.4%) i/s - 43.594M in 5.008124s direct 20.391M (± 7.0%) i/s - 103.546M in 5.105176s Comparison: direct: 20391490.9 i/s send: 8756908.0 i/s - 2.33x slower
  10. Conclusion 1. GraphQL Ruby is twice faster than last year!

    2. Consider total number of fields a. Especially if you’re going to add some codes which affect all fields 3. Enjoy Talk Driven Development