Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Learning from performance improvements on Graph...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Fumiaki MATSUSHIMA
September 13, 2023
Technology
1
1.3k
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
Share
More Decks by Fumiaki MATSUSHIMA
See All by Fumiaki MATSUSHIMA
Ruby で作る Ruby (物理)
mtsmfm
1
260
GraphQL Ruby benchmark
mtsmfm
1
880
タイムアウトにご用心 / Timeout might break application state
mtsmfm
6
2.7k
Build REST API with GraphQL Ruby
mtsmfm
0
380
GraphQL Ruby をちょっとだけ速くした / Make graphql-ruby faster a bit
mtsmfm
1
770
Gaming PC on GCP
mtsmfm
0
800
How to introduce GraphQL to an existing React-Redux application
mtsmfm
1
290
Canary release in StudySapuri
mtsmfm
0
3.2k
Analyze Rails CI
mtsmfm
2
1k
Other Decks in Technology
See All in Technology
組織のSREを推進するためのPlatform EngineeringとEKS / Platform Engineering and EKS to drive SRE in your organization
chmikata
0
180
競争優位を生み出す戦略的内製開発の実践技法
masuda220
PRO
2
530
dbt meetup #19 『dbtを『なんとなく動かす』を卒業します』
tiltmax3
0
150
サンタコンペ2025完全攻略 ~お前らの焼きなましは遅すぎる~
terryu16
1
570
脱・コピペ!自分で調べて書くK8sマニフェスト
devops_vtj
0
110
What's new in Go 1.26?
ciarana
2
280
Digitization部 紹介資料
sansan33
PRO
1
7k
Serverless Agent Architecture on Azure / serverless-agent-on-azure
miyake
1
130
LLM活用の壁を超える:リクルートR&Dの戦略と打ち手
recruitengineers
PRO
1
210
技術的負債の泥沼から組織を救う3つの転換点
nwiizo
4
850
自動テストが巻き起こした開発プロセス・チームの変化 / Impact of Automated Testing on Development Cycles and Team Dynamics
codmoninc
1
920
Lookerの最新バージョンv26.2がやばい話
waiwai2111
1
150
Featured
See All Featured
Code Review Best Practice
trishagee
74
20k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
10k
Accessibility Awareness
sabderemane
0
71
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
130
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
Optimising Largest Contentful Paint
csswizardry
37
3.6k
Leading Effective Engineering Teams in the AI Era
addyosmani
9
1.7k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Stewardship and Sustainability of Urban and Community Forests
pwiseman
0
130
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
110
What does AI have to do with Human Rights?
axbom
PRO
1
2k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Transcript
@mtsmfm Learning from performance improvements on GraphQL Ruby
Fumiaki Matsushima GitHub, Twitter @mtsmfm
https://www.meetup.com/ja-JP/GraphQL-Tokyo/
https://autify.com/
https://autify.com/careers
https://www.youtube.com/watch?v=dvip2PXi52Y&t=1875s
None
None
Summary of my last talk - GraphQL Ruby 2.0.13 (the
latest version at that time) is twice slower than 1.5.15
Since 2.0.13, there have been 17 releases! https://rubygems.org/gems/graphql/versions
Benchmark target type Article { field0: String! field1: String! ...
fieldN: String! } type Query { articles: [Article!]! } query { articles { field0, field1, ..., fieldN } }
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
Run benchmark on GitHub Actions https://github.com/mtsmfm/graphql-ruby-benchmark/pull/4
Run benchmark on GitHub Actions https://github.com/mtsmfm/graphql-ruby-benchmark/pull/4
Run benchmark on GitHub Actions https://github.com/mtsmfm/graphql-ruby-benchmark/pull/4
Benchmark env - GitHub Actions (ubuntu-latest) - Ruby 3.2.2 -
https://github.com/mtsmfm/graphql-ruby-benchmark
None
None
Many performance improvements https://github.com/rmosolgo/graphql-ruby/blob/904e8c595637450 40b6d05c5ecb22a73a320c7b5/CHANGELOG.md
None
None
PR #4399 https://github.com/rmosolgo/graphql-ruby/pull/4399
PR #4399 https://github.com/rmosolgo/graphql-ruby/pull/4399
PR #4399 https://github.com/rmosolgo/graphql-ruby/pull/4399
PR #4399 https://github.com/rmosolgo/graphql-ruby/pull/4399
PR #4399 1. Introduces CurrentState class to store runtime state
2. Removes unnecessary context lookup
PR #4399 1. Introduces CurrentState class to store runtime state
2. Removes unnecessary context lookup
Previous code
Previous code
PR #4399 https://github.com/rmosolgo/graphql-ruby/pull/4399
Referring context takes time?!
Context#[] https://github.com/rmosolgo/graphql-ruby/blob/904e8c59563745040b6d05c5ec b22a73a320c7b5/lib/graphql/query/context.rb#L124-L141
Context#[] https://github.com/rmosolgo/graphql-ruby/blob/904e8c59563745040b6d05c5ec b22a73a320c7b5/lib/graphql/query/context.rb#L124-L141 Hash like Hash Set
Looks fast enough 🤔
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
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!
Learning from PR #4399 1. Field related code can be
a hotspot a. Even context lookup
Context#[] https://github.com/rmosolgo/graphql-ruby/blob/904e8c59563745040b6d05c5ec b22a73a320c7b5/lib/graphql/query/context.rb#L124-L141
It changes [key] to public_send(key) https://github.com/rmosolgo/graphql-ruby/pull/4399/files#diff-2c8869b38ea62e6 9d0aa4fc7e571e6dc3b8c9f05fba9c25bc79fc17cfee2a335
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
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
2% improvements https://github.com/rmosolgo/graphql-ruby/pull/4631
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