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
Building a toolkit to detect performance regres...
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Kir Shatrov
April 22, 2015
Programming
6k
3
Share
Building a toolkit to detect performance regressions in Ruby on Rails core
My talk from RailsConf 2015.
Kir Shatrov
April 22, 2015
More Decks by Kir Shatrov
See All by Kir Shatrov
Running Jobs at Scale
kirs
1
230
Operating Rails in Kubernetes
kirs
3
500
RailsClub 2016
kirs
2
330
Performance regressions in Ruby on Rails Core
kirs
0
230
Развертывание веб-приложений и фреймворк Capistrano
kirs
1
300
Capistrano 3
kirs
4
3k
Other Decks in Programming
See All in Programming
誰も頼んでない機能を出荷した話
zekutax
0
140
タクシーアプリ『GO』の バックエンド開発のおける AI利活用と若者のすべて
pyama86
3
1.7k
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
670
Transactional Change Stream Processing With Debezium and Apache Flink
gunnarmorling
1
130
Copilot CLI の継戦能力を高める コンテキスト管理
nozomutu
1
1k
Java × distroless で 軽量なコンテナイメージを / Java on Distroless
contour_gara
0
320
These Five Tricks Can Make Your Apps Greener, Cheaper, & Nicer
hollycummins
0
210
AI時代の仕事技芸論 — ソフトウェア開発で「遊ぶように働く」職人的熟達のすすめ
kuranuki
0
210
AI Agent と正しく分析するための環境作り
yoshyum
3
610
密結合なバックエンドから TypeScript のコードを生成する
kemuridama
1
360
UaaL×Androidアプリのメモリ計測 — Memory Profilerの先へ
rio432
0
180
Inspired By RubyKaigi (EN)
atzzcokek
0
110
Featured
See All Featured
Fireside Chat
paigeccino
42
3.9k
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
520
Fashionably flexible responsive web design (full day workshop)
malarkey
408
66k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
350
YesSQL, Process and Tooling at Scale
rocio
174
15k
How to optimise 3,500 product descriptions for ecommerce in one day using ChatGPT
katarinadahlin
PRO
1
3.6k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
270
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.5k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
380
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Transcript
Kir Shatrov, RailsConf 2015 Building a toolkit to detect 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
None
None
None
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
Full app benchmark before
stackprof by Aman Gupta github.com/tmm1/stackprof
4.2 4.1
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.evilmartians.io 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/ruby/ruby webhook web app docker server benchmark suite
None
github.com/ruby-bench web app docker files benchmark suite
github.com/ruby-bench web app docker files benchmark suite
github.com/ruby-bench web app docker files benchmark suite
github.com/ruby-bench web app docker files benchmark suite
Results
Running builds for Rails
250k builds for Ruby
MRI performance regression caught
What’s next?
What’s next Pull Request benchmarks Weekly reports JRuby support
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
bit.ly/railsperf-gh github.com/rubybench bit.ly/railsperf-static
Thanks! @kirs @kirshatrov @evilmartians evilmartians.com