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
570
[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
[Kaigi on Rails 2024] Rails Way, or the highway
palkan
7
9.2k
[SF Ruby #7] Forms on Rails
palkan
0
14
[RubyKaigi 2024] Ruby Mixology 101: adding shots of PHP, Elixir, and more
palkan
2
910
[SF Ruby, March 2024] Rails on Wasm
palkan
4
1k
[Sin City Ruby 2024] Seven deadly Rails anti-patterns
palkan
3
1.5k
[Helvetic Ruby 2023] Profiling Ruby tests with Swiss precision
palkan
0
1.3k
[RailsWorld 2023] Untangling cables & demystifying twisted transistors
palkan
1
2.7k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
[RubyConf 2022] Weaving & seaming mocks
palkan
0
1.2k
Other Decks in Programming
See All in Programming
NSOutlineView何もわからん:( 前編 / I Don't Understand About NSOutlineView :( Pt. 1
usagimaru
0
220
Golang と Erlang
taiyow
8
1.9k
Tuning GraphQL on Rails
pyama86
2
1.2k
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
410
AWS IaCの注目アップデート 2024年10月版
konokenj
3
3.2k
Googleのテストサイズを活用したテスト環境の構築
toms74209200
0
290
Quine, Polyglot, 良いコード
qnighy
4
530
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
110
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4.2k
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.4k
Honoの来た道とこれから
yusukebe
19
3.1k
Identifying User Idenity
moro
6
8.7k
Featured
See All Featured
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
Building Better People: How to give real-time feedback that sticks.
wjessup
363
19k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
43
6.6k
Ruby is Unlike a Banana
tanoku
96
11k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Learning to Love Humans: Emotional Interface Design
aarron
272
40k
Automating Front-end Workflow
addyosmani
1366
200k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.2k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Optimizing for Happiness
mojombo
376
69k
Speed Design
sergeychernyshev
24
580
Typedesign – Prime Four
hannesfritz
39
2.4k
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!