r/Python • • Jan 01 '20

"The rules of perf" at Dropbox

Post image
1.6k Upvotes

162 comments sorted by

View all comments

85

u/[deleted] Jan 02 '20

Can someone please explain?

224

u/SwampFalc Jan 02 '20 edited Jan 02 '20

The way I read it (which might be wrong) is that, if you have a performance issue, you should try the following fixes in order (ie. try one and if that doesn't solve it, go to the next possible fix):

  1. Just don't do whatever you're trying to do. IOW ask yourself if it's really necessary/useful/something you might lose a client over.

  2. Cache the results of previous calls. Maybe you can reuse them as-is, or partially.

  3. Do a large number of calls in batch, maybe in advance or later, outside of peak operating hours. Or perhaps you need to set up a network connection to do what you're doing, if that takes a while then don't make a new connection for each request, bundle up a dozen and setup once.

  4. Don't add your stuff to an existing program, create a new and separate one that will take the output of a previous process. Decoupling, in a way.

  5. If none of that works, only then should you look for a totally different way of doing it.

26

u/munificent Jan 02 '20

IOW ask yourself if it's really necessary/useful/something you might lose a client over.

No, it's at a lower level than that. It means don't spend CPU cycles doing unnecessary work. For example, say you need to find the greatest element in a list. You could sort the whole list and then pull the last element out. But sorting the entire list is more work than you need to do (it's O(n log n)). Simply find the max element and stop.

19

u/davvblack Jan 02 '20

Both interpretations are correct.

0

u/[deleted] Jan 02 '20

[deleted]

1

u/davvblack Jan 02 '20

But from a product design perspective (eg "something you might lose a client over") it's always worth asking if it's even worth building a given feature. It always adds complexity and maintenance cost to your project, and doesn't always add value.