Senior Track Roadmap

Performance: O-notation

This course covers O-notation as a decision tool for Rails code. It explains what the notation claims and what it discards: constants, lower-order terms and the machine. It walks through five growth curves using concrete pairs, such as a query per record against one query. Later lessons cover the accidental quadratic from include? on an array, space complexity, and average, amortized and worst case. The course closes with the point where two curves cross and with when the analysis is worth doing.

What you'll learn

  • ✓What O-notation claims and what it leaves out
  • ✓The five growth curves common in Rails code
  • ✓Finding and fixing include? inside a loop with Set or index_by
  • ✓Space complexity and the memory cost of Active Record objects
  • ✓The difference between average, amortized and worst case
  • ✓Computing where two curves cross and deciding which side your data is on
Free preview · Lesson 1 5 min read

What O-notation is for, and what it hides

A code review comment says "this is O(n squared), rewrite it". The loop runs over a user's enrolled courses. The whole catalogue is a few hundred courses, and a learner is typically enrolled in a handful. The rewrite would save microseconds and cost a reviewer an afternoon.

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...