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

Speed Science

Speed Science

Run your app faster, with less RAM and a quicker boot time today. How? With science! In this talk we'll focus on the process of turning performance problems into reproducible bugs we can understand and squash. We'll look at real world use cases where small changes resulted in huge real world performance gains. You'll walk away with concrete and actionable advice to improve the speed of your app, and with the tools to equip your app for a lifetime of speed. Live life in the fast lane, with science!

Richard Schneeman

April 21, 2015
Tweet

More Decks by Richard Schneeman

Other Decks in Programming

Transcript

  1. BTW

  2. ER

  3. GO

  4. RAM

  5. Memory “1” “2” “3”“4” “5” “6” “7” RETAINED = []

    1.upto(100_000_000).each do |i| RETAINED << “#{i}” end
  6. def make_objects array = [] 1.upto(100_000_000).each do |i| array <<

    "#{i}" end return nil end make_objects GC.start(full_mark: true, immediate_sweep: true)
  7. def make_objects array = [] 1.upto(100_000_000).each do |i| array <<

    "#{i}" end return nil end make_objects GC.start(full_mark: true, immediate_sweep: true)
  8. def make_objects array = [] 1.upto(100_000_000).each do |i| array <<

    "#{i}" end return nil end make_objects GC.start(full_mark: true, immediate_sweep: true)
  9. WAT

  10. GC.start(full_mark: true, immediate_sweep: true) GC.disable # Code goes here before

    = GC.stat[:total_freed_objects] GC.enable GC.start(full_mark: true, immediate_sweep: true) after = GC.stat[:total_freed_objects] # => “Objects cleared by GC: 100_010_687”
  11. allocated memory by gem ----------------------------------- rack-1.5.2 x 6491 actionpack-4.1.2 x

    4888 hashie-3.3.1 x 4735 <============== activesupport-4.1.2 x 3292 omniauth-1.2.2 x 1387 actionview-4.1.2 x 1107 ruby-2.1.2/lib x 1097 railties-4.1.2 x 925 activerecord-4.1.2 x 440 warden-1.2.3 x 200 codetriage-test-app/app x 40 other x 40
  12. active_record/connection_adapters/postgresql_adapter: 2.2734375 active_record/connection_adapters/postgresql_adapter: 2.2734 mb active_record/connection_adapters/postgresql/oid: 0.8555 mb will_paginate/active_record: 1.4921875

    will_paginate/active_record: 1.4922 mb active_support/all: 1.01171875 active_support/all: 1.0117 mb active_support/core_ext: 0.9727 mb rack/test: 0.875 rack/test: 0.875 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/user: 0.734375 /Users/richardschneeman/Documents/projects/codetriage/app/models/user: 0.7344 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/repo: 0.50390625 /Users/richardschneeman/Documents/projects/codetriage/app/models/repo: 0.5039 mb new_relic/control/frameworks/rails4: 0.42578125 new_relic/control/frameworks/rails4: 0.4258 mb new_relic/control/frameworks/rails3: 0.3867 mb benchmark/ips: 0.4140625 benchmark/ips: 0.4141 mb will_paginate/view_helpers/action_view: 0.32421875 will_paginate/view_helpers/action_view: 0.3242 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/issue: 0.31640625 /Users/richardschneeman/Documents/projects/codetriage/app/models/issue: 0.3164 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/repo_subscription: 0.2734375 /Users/richardschneeman/.gem/ruby/2.2.1/gems/devise-3.4.1/app/mailers/devise/mailer: 0.265625 sprockets/base: 0.23046875 active_support/cache/dalli_store: 0.22265625 /Users/richardschneeman/Documents/projects/codetriage/app/models/issue_assignment: 0.18359375 /Users/richardschneeman/Documents/projects/codetriage/app/controllers/users/after_signup_controller: 0.18359375 /Users/richardschneeman/.gem/ruby/2.2.1/gems/wicked-1.0.0/app/controllers/wicked/wizard_controller: 0.1796875 /Users/richardschneeman/Documents/projects/codetriage/app/mailers/user_mailer: 0.1796875 /Users/richardschneeman/.gem/ruby/2.2.1/gems/devise-3.4.1/app/controllers/devise/ confirmations_controller: 0.17578125 /Users/richardschneeman/Documents/projects/codetriage/app/controllers/repos_controller: 0.17578125
  13. active_record/connection_adapters/postgresql_adapter: 2.2734375 active_record/connection_adapters/postgresql_adapter: 2.2734 mb active_record/connection_adapters/postgresql/oid: 0.8555 mb will_paginate/active_record: 1.4921875

    will_paginate/active_record: 1.4922 mb active_support/all: 1.01171875 active_support/all: 1.0117 mb active_support/core_ext: 0.9727 mb rack/test: 0.875 rack/test: 0.875 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/user: 0.734375 /Users/richardschneeman/Documents/projects/codetriage/app/models/user: 0.7344 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/repo: 0.50390625 /Users/richardschneeman/Documents/projects/codetriage/app/models/repo: 0.5039 mb new_relic/control/frameworks/rails4: 0.42578125 new_relic/control/frameworks/rails4: 0.4258 mb new_relic/control/frameworks/rails3: 0.3867 mb benchmark/ips: 0.4140625 benchmark/ips: 0.4141 mb will_paginate/view_helpers/action_view: 0.32421875 will_paginate/view_helpers/action_view: 0.3242 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/issue: 0.31640625 /Users/richardschneeman/Documents/projects/codetriage/app/models/issue: 0.3164 mb /Users/richardschneeman/Documents/projects/codetriage/app/models/repo_subscription: 0.2734375 /Users/richardschneeman/.gem/ruby/2.2.1/gems/devise-3.4.1/app/mailers/devise/mailer: 0.265625 sprockets/base: 0.23046875 active_support/cache/dalli_store: 0.22265625 /Users/richardschneeman/Documents/projects/codetriage/app/models/issue_assignment: 0.18359375 /Users/richardschneeman/Documents/projects/codetriage/app/controllers/users/after_signup_controller: 0.18359375 /Users/richardschneeman/.gem/ruby/2.2.1/gems/wicked-1.0.0/app/controllers/wicked/wizard_controller: 0.1796875 /Users/richardschneeman/Documents/projects/codetriage/app/mailers/user_mailer: 0.1796875 /Users/richardschneeman/.gem/ruby/2.2.1/gems/devise-3.4.1/app/controllers/devise/ confirmations_controller: 0.17578125 /Users/richardschneeman/Documents/projects/codetriage/app/controllers/repos_controller: 0.17578125
  14. application: 60.8242 mb mail: 39.2734 mb mail/parsers: 19.2461 mb mail/parsers/ragel:

    18.7031 mb mail/parsers/ragel/ruby: 18.6797 mb mail/parsers/ragel/ruby/machines/address_lists_machine: 7.2734 mb mail/parsers/ragel/ruby/machines/received_machine: 4.7578 mb mail/parsers/ragel/ruby/machines/envelope_from_machine: 2.2305 mb mail/parsers/ragel/ruby/machines/message_ids_machine: 1.5625 mb mail/parsers/ragel/ruby/machines/date_time_machine: 0.5977 mb mail/parsers/ragel/ruby/machines/content_disposition_machine: 0.4961 mb mail/parsers/ragel/ruby/machines/content_type_machine: 0.4648 mb mail/parsers/ragel/ruby/machines/content_location_machine: 0.3359 mb mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine: 0.3281 mb mail/parsers/ragel/ruby/machines/phrase_lists_machine: 0.3086 mb mime/types: 18.4922 mb mail/field: 0.3125 mb
  15. application: 60.8242 mb mail: 39.2734 mb mail/parsers: 19.2461 mb mail/parsers/ragel:

    18.7031 mb mail/parsers/ragel/ruby: 18.6797 mb mail/parsers/ragel/ruby/machines/address_lists_machine: 7.2734 mb mail/parsers/ragel/ruby/machines/received_machine: 4.7578 mb mail/parsers/ragel/ruby/machines/envelope_from_machine: 2.2305 mb mail/parsers/ragel/ruby/machines/message_ids_machine: 1.5625 mb mail/parsers/ragel/ruby/machines/date_time_machine: 0.5977 mb mail/parsers/ragel/ruby/machines/content_disposition_machine: 0.4961 mb mail/parsers/ragel/ruby/machines/content_type_machine: 0.4648 mb mail/parsers/ragel/ruby/machines/content_location_machine: 0.3359 mb mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine: 0.3281 mb mail/parsers/ragel/ruby/machines/phrase_lists_machine: 0.3086 mb mime/types: 18.4922 mb mail/field: 0.3125 mb
  16. To