Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[RailsConf 2024] From slow to go: Rails profili...

[RailsConf 2024] From slow to go: Rails profiling hands-on

Vladimir Dementyev

May 08, 2024
Tweet

More Decks by Vladimir Dementyev

Other Decks in Programming

Transcript

  1. 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
  2. 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
  3. palkan_tula palkan 🔍 Identify slowness causes and patterns 💊 Treat

    them well 🔁 Repeat until satisfied 7 From slow to go
  4. palkan_tula palkan Specialized profiler for Ruby test suites Optimization toolbox

    to speed up tests with less refactoring 9 TestProf test-prof.evilmartians.io
  5. 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
  6. 13

  7. 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)
  8. palkan_tula palkan General profiling (Stackprof, Vernier, sampling) Focused profiling (TagProf,

    EventProf) Factories overhead elimination (let_it_be) 16 The plan
  9. palkan_tula palkan Local time: 8 : 30 ➡ 2 :

    30 CI time: 14 : 30 ➡ 8 : 00 17 Results
  10. 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
  11. 20

  12. 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
  13. 25

  14. 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
  15. palkan_tula palkan Similar tests has similar problems Focus on most

    time consuming test types, not individual outliers 28 Focused profiling
  16. 29

  17. 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
  18. 33

  19. palkan_tula palkan Factory cascades Too many disposable records (no reuse

    or recycle) Create vs. build 38 Factories vs. slow tests
  20. 39

  21. palkan_tula palkan No cascades found Many tests share the same

    context Reusing records between examples brings up to 6x speed up! 41 Findings
  22. 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
  23. palkan_tula palkan Every file must be treated individually (routine) Extracting

    shared contexts may help simplify future optimizations (e.g., adding fixtures) 43 Findings
  24. palkan_tula palkan Discover more TestProf tools (Autopilot, RuboCop cops, Factory

    Doctor) Make YOUR tests faster Become a Mastodon contributor! 45 Homework