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

Hotspot on Coverage

Hotspot on Coverage

RubyKaigi 2024 LT


May 16, 2024

More Decks by Shia

Other Decks in Programming


  1. Self introduction - Sangyong Sim @ STORES. Inc - shia

    @ Internet - riseshia @ {X, GitHub} Favorite library: coverage Favorite contest: ISUCON 2
  2. - Iikanjini Speed Up Contest - Scoring base on 1

    min benchmark with many languages (including Ruby) - Given Ruby app is a Rack application in most case. ISUCON 3
  3. Popular tool for profiling is stackprof, but I haven’t used

    it on the contest for several years. - It’s not easy to setup & use properly - flamegraph is too verbose on starting point, source notation is hard to read (when app.rb has more than 1k rows) Profiling Ruby app on ISUCON 4
  4. What I want was just find out code hotspot to

    optimize. App has small gem dependencies, most important codes are in app, not gem. Could counting code execution be enough in this case…? so… Profiling Ruby app on ISUCON 5
  5. - Call “Coverage.start” on start - Insert Rack middleware to

    app, which adds path to coverage report page - Run benchmark - Visit web UI page Profiling with “coverage”!!!! 7
  6. Result - In this case, the approach was useful to

    find out where to start optimize - e.g. It might be less effective with Rails - akainaa is improved version from origin impl used on ISUCON 13 - https://github.com/riseshia/akainaa - akainaa is “It’s red…” in Japanese 8
  7. View: Why not simplecov-html or coverband? - These are designed

    to focus on unexecuted code - green background on executed code - red background on executed code - akainaa web view is designed to focus on line executed a lot - no background on unexecuted code - light red background on executed code with few call - red background on executed code with many call 10
  8. Akainaa vs simplecov-html on ISUCON 13 baseline impl benchmark 11

    Note: You can get & compare full reports from Akainaa repo (if you don’t mind ISUCON 13 spoiler)
  9. - Introduce akainaa, the gem helps record & visualize code

    hotspot on Rack application - Not only for ISUCON, This also helps to read complex rack application, too. - Please try it! Summary 13
  10. - “coverage” add count to only first line of multi-lined

    method call - Coloring args is better (IMO) - Impl with Prism Better coloring 15