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

Fast Rails (Beta)

Winston
January 27, 2015

Fast Rails (Beta)

This is a work-in-progress talk, subject to changes.

First given at RubySG's meetup on 27 Jan, 2015.

Winston

January 27, 2015
Tweet

More Decks by Winston

Other Decks in Programming

Transcript

  1. Fast Rails
    (Beta)

    View Slide

  2. Frontend
    Backend
    Database

    View Slide

  3. This slide intentionally left blank.

    View Slide

  4. Front End

    View Slide

  5. PageSpeed!
    https://developers.google.com/speed
    !
    YSlow!
    http://yslow.org/

    View Slide

  6. Asset Pipeline!
    Far Future Expires
    Minify JavaScript + CSS
    Minimize HTTP Requests
    Multiple Asset Hosts
    (http://api.rubyonrails.org/classes/ActionView/Helpers/AssetUrlHelper.html)

    View Slide

  7. Compression!
    http://nginx.org/en/docs/http/ngx_http_gzip_module.html
    https://github.com/romanbsd/heroku-deflater

    View Slide

  8. CDN!
    Static Assets
    Dynamic Content

    View Slide

  9. Browser Caching!
    `expires_in`, `expires_now`, `fresh_when`, `stale?`
    (http://api.rubyonrails.org/classes/ActionController/ConditionalGet.html)

    View Slide

  10. Assets Loading!
    Stylesheets at the Top
    JavaScripts at the Bottom (async)

    View Slide

  11. Images!
    `gem install smusher`
    Lazy Load

    View Slide

  12. FOUT!
    (Flash of Unstyled Text)
    https://github.com/typekit/webfontloader

    View Slide

  13. Turbolinks!
    mmmm…

    View Slide

  14. Backend

    View Slide

  15. Update!
    Ruby 2.2.0
    Rails 4.2

    View Slide

  16. Memory!
    Server
    Database

    View Slide

  17. Background Jobs!
    Email/Image Processing

    View Slide

  18. Data Storage!
    Save to S3?
    Delete from S3?

    View Slide

  19. Caching!
    Russian Doll Caching
    Low-Level Caching

    View Slide

  20. Views!
    helpers (inline) > partials > loop
    `render ‘article’, collection: @articles`

    View Slide

  21. Fast Ruby!
    https://github.com/JuanitoFatas/fast-ruby

    View Slide

  22. Fast Code!
    `exists` vs. `present?`
    Loop in Code vs. SQL

    View Slide

  23. Development!
    `spring`, `guard`

    View Slide

  24. Database

    View Slide

  25. ActiveRecord!
    Foreign Keys, Composite Keys, SQL Explain
    `find`/`find_by`/`find_by_` vs. `where(..).take`

    View Slide

  26. Indexes!
    Foreign Keys, Composite Keys, SQL Explain
    https://github.com/eladmeidar/rails_indexes

    View Slide

  27. n+1!
    `gem install bullet`

    View Slide

  28. The End
    (Beta)

    View Slide