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

How Airbnb Made Specs Run 2.5x Faster

Brian Morearty
August 10, 2015
180

How Airbnb Made Specs Run 2.5x Faster

You're a developer on a large, legacy Rails project with thousands of specs. You hate waiting for them to run. If you sit and watch the dots go by, you're wasting time doing nothing. But if you go on Hacker News to do some other work, you lose your flow and it takes you too long to get back to it. It's a lose-lose. Is it impossible to speed up specs on a large Rails project? At Airbnb, two engineers made our specs run 2.5x faster in a three-day hackathon project. We did this without rewriting any specs. Multiple engineers had told us they had already tried to speed up the specs and they didn't think there was much left that could be done. Learn what we did to diagnose and improve spec performance.

Brian Morearty

August 10, 2015
Tweet

Transcript

  1. /usr/bin/ruby1.9.1 Total samples: 36234 Focusing on: 36234 Dropped nodes with

    <= 181 abs(samples) Dropped edges with <= 36 samples BasicObject#instance_exec 14 (0.0%) of 19941 (55.0%) 9 5 0 2 Array#map 44 (0.1%) of 18478 (51.0%) 4 2 3 FactoryGirl FactoryRunner#run 2 (0.0%) of 15382 (42.5%) 8 6 9 8 FactoryGirl E v a l u a t o r # a s s o c i a t i o n 0 (0.0%) of 4791 (13.2%) 6 4 6 4 C l a s s # r u n 0 (0.0%) of 19363 (53.4%) R S p e c C o r e R u n n e r # r u n 0 (0.0%) of 18658 (51.5%) 1 8 5 2 5 2 5 5 7 9 C l a s s # r u n _ e x a m p l e s 0 (0.0%) of 18111 (50.0%) 1 7 9 9 4 R S p e c C o r e R e p o r t e r # r e p o r t 0 (0.0%) 1 7 4 6 8 4 3 4 6 3 RSpec Core Example#run 1 (0.0%) of 18281 (50.5%) 1 8 2 0 0 4 2 5 R S p e c C o r e Example#with_around_each_hooks 0 (0.0%) of 18360 (50.7%) R S p e c C o r e E x a m p l e # r u n _ b e f o r e _ e a c h 0 (0.0%) 8 9 1 0 1 8 2 6 4 1 8 1 1 1 1 7 6 3 4 garbage_collector 15558 (42.9%) Module#instrument 1 (0.0%) of 15379 (42.4%) 2 4 4 6 9 9 1 2 2 FactoryGirl S t r a t e g y C r e a t e # a s s o c i a t i o n 0 (0.0%) of 4684 (12.9%) 6 3 9 0 6 3 9 1
  2. 1.61x as fast. 0%# 10%# 20%# 30%# 40%# 50%# 60%#

    70%# 80%# 90%# 100%# Before# Tune#GC# Op9mize#user#factory# Op9mize#index# enforcer# UserEcrea9on# background#jobs# Disable#upshot#in# specs# Bonus:#backport# `pluck`#
  3. 1.28x as fast. 0%# 10%# 20%# 30%# 40%# 50%# 60%#

    70%# 80%# 90%# 100%# Before# Tune#GC# Op9mize#user#factory# Op9mize#index# enforcer# UserEcrea9on# background#jobs# Disable#upshot#in# specs# Bonus:#backport# `pluck`#
  4. 1.06x as fast. 0%# 10%# 20%# 30%# 40%# 50%# 60%#

    70%# 80%# 90%# 100%# Before# Tune#GC# Op9mize#user#factory# Op9mize#index# enforcer# UserEcrea9on# background#jobs# Disable#upshot#in# specs# Bonus:#backport# `pluck`#
  5. 1.10x as fast. 0%# 10%# 20%# 30%# 40%# 50%# 60%#

    70%# 80%# 90%# 100%# Before# Tune#GC# Op9mize#user#factory# Op9mize#index# enforcer# UserEcrea9on# background#jobs# Disable#upshot#in# specs# Bonus:#backport# `pluck`#
  6. 1.06x as fast. 0%# 10%# 20%# 30%# 40%# 50%# 60%#

    70%# 80%# 90%# 100%# Before# Tune#GC# Op9mize#user#factory# Op9mize#index# enforcer# UserEcrea9on# background#jobs# Disable#upshot#in# specs# Bonus:#backport# `pluck`#