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
Fumiaki MATSUSHIMA
September 13, 2023
Technology
1
1k
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
180
GraphQL Ruby benchmark
mtsmfm
1
740
タイムアウトにご用心 / Timeout might break application state
mtsmfm
6
2.5k
Build REST API with GraphQL Ruby
mtsmfm
0
280
GraphQL Ruby をちょっとだけ速くした / Make graphql-ruby faster a bit
mtsmfm
1
680
Gaming PC on GCP
mtsmfm
0
680
How to introduce GraphQL to an existing React-Redux application
mtsmfm
1
220
Canary release in StudySapuri
mtsmfm
0
2.9k
Analyze Rails CI
mtsmfm
2
800
Other Decks in Technology
See All in Technology
alecthomas/kong はいいぞ / kamakura.go#7
fujiwara3
1
300
ハイテク休憩
sat
PRO
2
140
統計データで2024年の クラウド・インフラ動向を眺める
ysknsid25
2
840
re:Invent をおうちで楽しんでみた ~CloudWatch のオブザーバビリティ機能がスゴい!/ Enjoyed AWS re:Invent from Home and CloudWatch Observability Feature is Amazing!
yuj1osm
0
120
終了の危機にあった15年続くWebサービスを全力で存続させる - phpcon2024
yositosi
0
280
Amazon VPC Lattice 最新アップデート紹介 - PrivateLink も似たようなアップデートあったけど違いとは
bigmuramura
0
190
祝!Iceberg祭開幕!re:Invent 2024データレイク関連アップデート10分総ざらい
kniino
2
250
Fanstaの1年を大解剖! 一人SREはどこまでできるのか!?
syossan27
2
160
継続的にアウトカムを生み出し ビジネスにつなげる、 戦略と運営に対するタイミーのQUEST(探求)
zigorou
0
520
AWS re:Invent 2024 ふりかえり
kongmingstrap
0
130
Wantedly での Datadog 活用事例
bgpat
1
430
KnowledgeBaseDocuments APIでベクトルインデックス管理を自動化する
iidaxs
1
260
Featured
See All Featured
How to Think Like a Performance Engineer
csswizardry
22
1.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
28
2.1k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Java REST API Framework Comparison - PWX 2021
mraible
PRO
28
8.3k
How STYLIGHT went responsive
nonsquared
95
5.2k
Documentation Writing (for coders)
carmenintech
66
4.5k
The Cult of Friendly URLs
andyhume
78
6.1k
The Language of Interfaces
destraynor
154
24k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
365
25k
Writing Fast Ruby
sferik
628
61k
Building Your Own Lightsaber
phodgson
103
6.1k
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