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
Performance regressions in Ruby on Rails Core
Search
Kir Shatrov
September 27, 2015
Programming
230
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Performance regressions in Ruby on Rails Core
Slides for my Railsclub Moscow 2015 talk.
Kir Shatrov
September 27, 2015
More Decks by Kir Shatrov
See All by Kir Shatrov
Running Jobs at Scale
kirs
1
240
Operating Rails in Kubernetes
kirs
3
500
RailsClub 2016
kirs
2
330
Building a toolkit to detect performance regressions in Ruby on Rails core
kirs
3
6.1k
Развертывание веб-приложений и фреймворк Capistrano
kirs
1
300
Capistrano 3
kirs
4
3k
Other Decks in Programming
See All in Programming
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
160
Go1.27で導入されるジェネリクスメソッドでできること
mackee
0
120
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
230
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
540
エンジニアと一緒にテストコードの設計と実装を改善した話
mototakatsu
0
160
代数的データ型って何が嬉しいの? #frontend_phpcon_do
kajitack
8
3.6k
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
2k
正しくソフトウェアを作る、前提を疑うための認知の視点 / doubt-premise
minodriven
21
6.6k
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2.1k
セキュリティの専門家じゃなくてもできる。「セキュリティ意識」をアップデートして サプライチェーン攻撃への耐性を高めよう。
tk3fftk
5
740
「エンジニアインターン、どうやって取った?」準備のリアルを語るLT会 Progate BAR
akiomatic
0
130
ふつうのFeature Flag実践入門
irof
7
3.8k
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
250
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
For a Future-Friendly Web
brad_frost
183
10k
Skip the Path - Find Your Career Trail
mkilby
1
150
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.8k
Darren the Foodie - Storyboard
khoart
PRO
3
3.4k
Odyssey Design
rkendrick25
PRO
2
700
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
390
Amusing Abliteration
ianozsvald
1
200
The Director’s Chair: Orchestrating AI for Truly Effective Learning
tmiket
1
190
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.3k
Transcript
RAILSCLUB 2015 Kir Shatrov Performance regressions in Ruby on Rails
core
@kirs @kirshatrov !"
None
Catching Performance Regressions in Rails
What’s a performance regression?
What’s a performance regression in Rails?
Page load 250ms → 4s
Case Study
4.2rc1
None
2 times slower
4.2rc3
Faster framework = Faster app
Examples from Rails commits
Metrics
Timing & Allocations
Faster Methods = Faster App
start = Time.now.to_f sleep 5 ends = Time.now puts "it
took #{ends - start}"
Allocations = GC work Less allocations = less GC work
before = GC.stat[:total_allocated_object] 10_000.times do { "key" => "value" }
end after = GC.stat[:total_allocated_object] puts "allocated: #{after - before}"
Basic primitives
Examples from Rails commits String
None
None
None
None
None
None
None
None
None
None
Examples from Rails commits Hash
None
None
None
None
None
None
Optimize only “hot” code
Track the changes
The Idea to build a service
Track it with benchmarks
Any existing benchmarks?
None
Setup Discourse Populate records Start Unicorn with RAILS_ENV=production Make requests
with Apache Bench to the list of endpoints Print timings and memory usage
Components to benchmark activerecord activemodel actionview actioncontroller activesupport
3.2 – 4.0 – 4.1 – 4.2
higher is faster
higher is faster
higher is faster
None
ActiveRecord Finders require_relative 'support/activerecord_base.rb' require_relative 'support/benchmark_rails.rb' User.create!(name: 'kir', email: '
[email protected]
')
m = Benchmark.rails(100, "activerecord/#{db_adapter}/finders") do User.find(1) end puts m.to_json
Disable GC is necessary Warm up the code Make N
iterations Calculate the mean timing and object allocations
ActiveRecord::Base#create require_relative 'support/activerecord_base.rb' require_relative 'support/benchmark_rails.rb' fields = { name: "Kir",
notes: "Note", created_at: Date.today } Benchmark.rails(1000, "activerecord/#{db_adapter}/create") do Exhibit.create(fields) end
Correct benchmarks
Full app benchmark higher is faster
Full app benchmark before higher is faster
stackprof by Aman Gupta github.com/tmm1/stackprof
config/environments/production.rb
Full app benchmark after
✅ Benchmarks
None
None
The Service
What do we want? See benchmark for every commit See
benchmark for every PR Report to PR author (“activerecord became 2% slower”) See charts
railsperf The prototype of the service. Built in January
rubybench.org by Sam Saffron and Guo Xiang Tan “Alan”
None
3.6GHz Intel® Xeon® E3-1270 v3 Quad-Core 4 x 8GB Micron
ECC Samsung SSD 845DC EVO - 240 GB Sponsored hardware
ruby-bench + rails
github.com/rails/rails webhook web app docker server benchmark suite
None
github.com/ruby-bench web app docker files benchmark suite
Results
Running builds for Rails
Performance regressions caught
Overview What is a performance regression How to track them
How to solve them How to write benchmarks Automate tracking!
How to track your app performance? Study how do Ruby
objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly
Ruby Under a Microscope
http://bit.ly/writing-fast-ruby
How to track your app performance? Study how do Ruby
objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly
Setup the app Populate records Start Unicorn with RAILS_ENV=production Make
requests with Apache Bench to the list of endpoints Print timings and memory usage
How to track your app performance? Study how do Ruby
objects work and how to treat them Write a Discourse-like benchmark and run it on Travis Subscribe to Rails Weekly
Спасибо! @kirs @kirshatrov @evilmartians evilmartians.com