Lock in $30 Savings on PRO—Offer Ends Soon! ⏳

Rails高速化戦略 / Speeding Up Rails

Rails高速化戦略 / Speeding Up Rails

Roppongi.rb#1( http://roppongirb.connpass.com/event/33502/ ) での発表スライドです。

- 本発表内容をまとめたブログ記事はこちら: http://blog.toshimaru.net/roppongirb-speeding-up-rails/

toshimaru

July 14, 2016
Tweet

More Decks by toshimaru

Other Decks in Technology

Transcript

  1. Ruby Version History • 2013.2: Ruby 2.0 • 2013.12: Ruby

    2.1 • 2014.12: Ruby 2.2 • 2015.12: Ruby 2.3 • 20xx: Ruby 3.0 Roppongi.rb #1 10
  2. ActiveRecord Optimization ! ໰୊ൃݟܕ • bullet: Kill N+1 issue! •

    activerecord-cause: Logs where ActiveRecord actually loads record Roppongi.rb #1 26
  3. ActiveRecord Optimization ! DBεΩʔϚ࠷దԽܕ • flag_shih_tzu: Bit fields for ActiveRecord

    • counter-cache: cacheing count query result • counter_culture: Better counter-cache Roppongi.rb #1 27
  4. N+1 partial rendering <%# views/items/index %> <% @items.each do |item|

    %> <%= render item %> <% end %> <%# views/items/_item %> <tr> <td><%= item.name %></td> <td><%= link_to 'Show', item %></td> <td><%= link_to 'Edit', edit_item_path(item) %></td> <td><%= link_to 'Destroy', item, method: :delete %></td> </tr> Roppongi.rb #1 31
  5. Log with N+1 rendering Processing by ItemsController#index as HTML Rendering

    items/index.html.erb within layouts/application Item Load (0.3ms) SELECT "items".* FROM "items" Rendered items/_item.html.erb (0.5ms) Rendered items/_item.html.erb (0.3ms) ...snip... Rendered items/_item.html.erb (0.5ms) Rendered items/_item.html.erb (0.3ms) Rendered items/index.html.erb within layouts/application (57.7ms) Completed 200 OK in 80ms (Views: 77.1ms | ActiveRecord: 0.3ms) Roppongi.rb #1 32
  6. Collection rendering <%# views/items/index %> <%= render @items %> <%#

    views/items/_item %> <tr> <td><%= item.name %></td> <td><%= link_to 'Show', item %></td> <td><%= link_to 'Edit', edit_item_path(item) %></td> <td><%= link_to 'Destroy', item, method: :delete %></td> </tr> Roppongi.rb #1 33
  7. Log without N+1 rendering Processing by ItemsController#index as HTML Rendering

    items/index.html.erb within layouts/application Item Load (0.4ms) SELECT "items".* FROM "items" Rendered collection of items/_item.html.erb [29 times] (6.9ms) Rendered items/index.html.erb within layouts/application (10.3ms) Completed 200 OK in 29ms (Views: 26.4ms | ActiveRecord: 0.4ms) Roppongi.rb #1 34
  8. [جຊฤ] ·ͱΊ • Ruby Version Up • ϘτϧωοΫ೺Ѳ => ௵͢

    • gemΛ༗ޮ׆༻ͯ͠ActiveRecord/ΫΤϦ࠷ద Խ • ύʔγϟϧϨϯμϦϯάΛݮΒ͢ Roppongi.rb #1 35
  9. 3 types of cacheing2 1. Fragment Cache: View fragment caching.

    2. Action Cache: Controller's action caching (removed in Rails4). 3. Page Cache: Static page caching (removed in Rails4). 2 Caching with Rails: An overview — Ruby on Rails Guides Roppongi.rb #1 38
  10. ⚡ AMP • Webߴ଎ԽͷϕετϓϥΫςΟεΛ٧ΊࠐΜͩ ࢓༷/੍ݶ • Why AMP is fast

    — Medium • Google AMP Cache: GoogleͰΩϟογϡͯ͠ ίϯςϯπ഑৴Λݞ୅ΘΓ • => Google AMP CDN Roppongi.rb #1 63
  11. ࢀߟࢿྉ • High Performance Rails (long edition) // Speaker Deck

    • RailsύϑΥʔϚϯεجຊͷΩ // Speaker Deck • 3x Rails // Speaker Deck • ΢ΣϒΛ଎͘͢ΔͨΊʹDeNA͕΍͍ͬͯΔ͜ ͱ - HTTP/2ͱɺ͞Βʹͦͷઌ Roppongi.rb #1 66
  12. ࢀߟࢿྉ • Rails Upgrade Casual Talks // Speaker Deck •

    σβΠφʔ΍σΟϨΫλʔ΋஌͓͖͍ͬͯͨɺ ϖʔδදࣔ଎౓ͷߴ଎Խͷجຊ – Rriver • ep22 AMP | mozaic.fm Roppongi.rb #1 67