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
[RailsConf 2024] From slow to go: Rails profili...
Search
Vladimir Dementyev
May 08, 2024
Programming
0
1.4k
[RailsConf 2024] From slow to go: Rails profiling hands-on
https://evilmartians.com/events/from-slow-to-go-rails-test-profiling-hands-on-railsconf-2024
Vladimir Dementyev
May 08, 2024
Tweet
Share
More Decks by Vladimir Dementyev
See All by Vladimir Dementyev
[SF Ruby] Presence ain't perfect
palkan
0
490
[WasmCon 2024] From client to server: Ruby on Rails on WebAssembly
palkan
0
870
[Kaigi on Rails 2024] Rails Way, or the highway
palkan
8
18k
[SF Ruby #7] Forms on Rails
palkan
0
45
[RubyKaigi 2024] Ruby Mixology 101: adding shots of PHP, Elixir, and more
palkan
2
1.3k
[SF Ruby, March 2024] Rails on Wasm
palkan
4
1.5k
[Sin City Ruby 2024] Seven deadly Rails anti-patterns
palkan
3
1.8k
[Helvetic Ruby 2023] Profiling Ruby tests with Swiss precision
palkan
0
1.7k
[RailsWorld 2023] Untangling cables & demystifying twisted transistors
palkan
1
4k
Other Decks in Programming
See All in Programming
大LLM時代にこの先生きのこるには-ITエンジニア編
fumiyakume
8
3.3k
データと事例で振り返るDevin導入の"リアル" / The Realities of Devin Reflected in Data and Case Studies
rkaga
1
530
MySQL初心者が311個のカラムにNot NULL制約を追加していってALTER TABLEについて学んだ話
hatsu38
2
110
Contribute to Comunities | React Tokyo Meetup #4 LT
sasagar
0
600
2025-04-25 GitHub Copilot Agent ライブデモ(スクリプト)
goataka
0
110
Optimizing JRuby 10
headius
0
580
eBPF超入門「o11yに使える」とは (20250424_eBPF_o11y)
thousanda
1
110
API for docs
soutaro
4
1.7k
状態と共に暮らす:ステートフルへの挑戦
ypresto
3
1.2k
Cursor/Devin全社導入の理想と現実
saitoryc
29
22k
マイコンでもRustのtestがしたい/KernelVM Kansai 11
tnishinaga
0
840
オープンソースコントリビュート入門
_katsuma
0
130
Featured
See All Featured
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
14
1.4k
Build The Right Thing And Hit Your Dates
maggiecrowley
35
2.7k
Thoughts on Productivity
jonyablonski
69
4.6k
Practical Orchestrator
shlominoach
187
11k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
52
2.5k
Embracing the Ebb and Flow
colly
85
4.7k
The Power of CSS Pseudo Elements
geoffreycrofte
75
5.8k
Reflections from 52 weeks, 52 projects
jeffersonlam
349
20k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
507
140k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
30
2.3k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
280
13k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
21k
Transcript
None
From slow to go: Rails test profiling hands-on Vladimir Dementyev
Evil Martians
palkan_tula palkan Why are we here? What's the plan? Who
are you? 3 Warming up Or waiting for everyone's dip rspec to pass
palkan_tula palkan You are here = = your tests are
slow 4
palkan_tula palkan Longer CI builds (also more expensive) Longer local
runs (or "local CI" builds) 5 Slow tests
palkan_tula palkan Longer CI builds (also more expensive) Longer local
runs (or "local CI" builds) Longer feedback loops More distraction, less productivity 6 Slow tests
palkan_tula palkan 🔍 Identify slowness causes and patterns 💊 Treat
them well 🔁 Repeat until satisfied 7 From slow to go
palkan_tula palkan 8
palkan_tula palkan Specialized profiler for Ruby test suites Optimization toolbox
to speed up tests with less refactoring 9 TestProf test-prof.evilmartians.io
palkan_tula palkan Used by GitHub, Discourse, Gitlab, Dev.to, and many
more Used by YOU at this workshop! 10 TestProf test-prof.evilmartians.io
11 github.com/palkan
12 evilmartians.com
13
palkan_tula palkan 14 X
palkan_tula palkan 15 Disclaimer: Mastodon team already did some test
performance work (via TestProf), so I had to revert a few optimizations in the workshop's version of the codebase (so we can have more fun)
palkan_tula palkan General profiling (Stackprof, Vernier, sampling) Focused profiling (TagProf,
EventProf) Factories overhead elimination (let_it_be) 16 The plan
palkan_tula palkan Local time: 8 : 30 ➡ 2 :
30 CI time: 14 : 30 ➡ 8 : 00 17 Results
palkan_tula palkan Rails tests occupy only for a portion of
a CI build time No need to optimize beyond other components 18 CI vs Rails tests
palkan_tula palkan General profiling 19
20
palkan_tula palkan Workshop instructions 21 # rails_helper.rb TestProf::EventProf.monitor( Paperclip::Attachment, 'paperclip.post_process',
:post_process )
palkan_tula palkan Workshop instructions 22 TAG_PROF=type \ TAG_PROF_FORMAT=html \ TAG_PROF_EVENT=sql.active_record,factory.create,
sidekiq.inline,paperclip.post_process \ be rspec
palkan_tula palkan Coverage: opt-out ➡ opt-in gem "debug", require: false
Webpacker: cache_manifest: true 23 Findings
palkan_tula palkan Logging—no effect when disk write is fast (SSD,
Docker volumes on Mac) Thousands of I18n YAMLs—handled by Bootsnap 24 Findings
25
palkan_tula palkan Do not require test-specific profiling skills Takes the
most significant amount of time (sampling helps) Highlights low-hanging fruits 26 General profiling
palkan_tula palkan Focused profiling 27
palkan_tula palkan Similar tests has similar problems Focus on most
time consuming test types, not individual outliers 28 Focused profiling
29
palkan_tula palkan Reduced the number of tests to analyze by
~2x Divided tests into smaller groups (~1min run time) for further analysis 30 Focused profiling
palkan_tula palkan TagProf EventProf RspecStamp (RSTAMP) 31 Tools
palkan_tula palkan Sidekiq: inline! ➡ fake! Paperclip::Testing.fake! 32 Findings
33
palkan_tula palkan Workshop instructions 34 # .rspec-local --tag ~paperclip:process
palkan_tula palkan 35 What's next?
palkan_tula palkan Factories 36
palkan_tula palkan 37 FPROF = 1 \ EVENT_PROF=factory.create \ be
rspec spec/models Workshop instructions
palkan_tula palkan Factory cascades Too many disposable records (no reuse
or recycle) Create vs. build 38 Factories vs. slow tests
39
palkan_tula palkan FactoryProf RSpecDissect before_all / let_it_be 40 Tools
palkan_tula palkan No cascades found Many tests share the same
context Reusing records between examples brings up to 6x speed up! 41 Findings
palkan_tula palkan Replacing let/let! with let_it_be works in ~90% of
tests The rest may require some refactoring (usually minor) 42 Findings
palkan_tula palkan Every file must be treated individually (routine) Extracting
shared contexts may help simplify future optimizations (e.g., adding fixtures) 43 Findings
palkan_tula palkan Homework 44
palkan_tula palkan Discover more TestProf tools (Autopilot, RuboCop cops, Factory
Doctor) Make YOUR tests faster Become a Mastodon contributor! 45 Homework
Thank you Visit TestProf and Evil Martians at the Hack
Day!