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

Rails performance optimisation tips

Rails performance optimisation tips

Alessandro Lepore

May 04, 2018
Tweet

More Decks by Alessandro Lepore

Other Decks in Programming

Transcript

  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...