Rails performance optimisation tips

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Rails performance optimisation tips

Alessandro Lepore

May 04, 2018

Annual Pro sale · Save $30

Have presentations of your own?

Share with private links, password protection, and more control over your work.

Transcript

15 slides
  1. DB is fast, Ruby is slow • SQL is awesome

    • SQL is complex • pluck instead of map • order instead of sort_by • any? instead of present? • size instead of count or length • find_each instead of all • select to limit fields • Avoid collection.to_a • N+1 queries are not always bad
  2. Tips • Measure • Avoid mistakes • Cache all the

    things! • Use recent Ruby versions • Try optimised gems (fast_blank, fast_jsonapi, concurrent-ruby-ext etc.) • Know your language (GC, Heap, Constant cache etc.) • Concurrency / background jobs • Ruby fine tuning (ENV vars tweaking, alternative malloc) • Also DevOp
  3. Tips • Limit response size, optimise images • Defer Javascripts

    • All those things that Rails is already doing ◦ Single file, minify, compress, hash etc. • HTTP headers • Limit connections • Split critical CSS • Limit or async web fonts • Use a CDN • Try new technologies: HTTP/2, WebP...

More Decks by Alessandro Lepore

Other Decks in Programming