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
2.9k
0
Share
[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
More Decks by Vladimir Dementyev
See All by Vladimir Dementyev
[RubyKaigi 2026] Require Hooks
palkan
1
290
[Tropical on Rails] From 1 to 2
palkan
1
49
[SF Ruby Feb'26] The Silicon Heel
palkan
0
210
[SF Ruby Conf 2025] Rails X
palkan
2
1k
[SF Ruby] Presence ain't perfect
palkan
0
1.1k
[WasmCon 2024] From client to server: Ruby on Rails on WebAssembly
palkan
0
1.9k
[Kaigi on Rails 2024] Rails Way, or the highway
palkan
8
27k
[SF Ruby #7] Forms on Rails
palkan
0
130
[RubyKaigi 2024] Ruby Mixology 101: adding shots of PHP, Elixir, and more
palkan
2
2k
Other Decks in Programming
See All in Programming
AI-DLC Deep Dive
yuukiyo
9
5.6k
Oxlintとeslint-plugin-react-hooks 明日から始められそう?
t6adev
0
320
ソフトウェア設計の結合バランス #phperkaigi
kajitack
0
490
How We Practice Exploratory Testing in Iterative Development( #scrumniigata ) / 反復開発の中で、探索的テストをどう実施しているか
teyamagu
PRO
3
710
セグメントとターゲットを意識するプロポーザルの書き方 〜採択の鍵は、誰に刺すかを見極めるマーケティング戦略にある〜
m3m0r7
PRO
0
750
20年以上続くプロダクトでも使い続けられる静的解析ツールを求めて
matsuo_atsushi
0
140
Agent Skills を社内で育てる仕組み作り
jackchuka
1
1.4k
JOAI2026 1st solution - heron0519 -
heron0519
0
180
属人化しないコード品質の作り方_2026.04.07.pdf
muraaano
0
310
WebAssembly を読み込むベストプラクティス 2026年春版 / Best Practices for Loading WebAssembly (Spring 2026)
petamoriken
5
1.1k
ついに来た!本格的なマルチクラウド時代の Google Cloud
maroon1st
0
380
検索設計から 推論設計への重心移動と Recall-First Retrieval
po3rin
5
1.5k
Featured
See All Featured
The SEO identity crisis: Don't let AI make you average
varn
0
460
Building Adaptive Systems
keathley
44
3k
How to Build an AI Search Optimization Roadmap - Criteria and Steps to Take #SEOIRL
aleyda
1
2k
A Modern Web Designer's Workflow
chriscoyier
698
190k
KATA
mclloyd
PRO
35
15k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
110
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
270
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
410
Automating Front-end Workflow
addyosmani
1370
200k
30 Presentation Tips
portentint
PRO
1
290
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
160
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
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!