Wednesday, October 26, 2011

Notes about Python optimization

Yesterday, Dropbox posted a story detailing how they optimized a frequently used function in their code.

http://tech.dropbox.com/?p=89

The conclusions are:
  1. String concatenation is more favored than string formatting.
  2. Built-in set and dict types are fast.
  3. Computing is more favored in C than Python. Try to minimize Python code with function inlining, implicit loop and move as much computing to C as possible, not necessarily your own C extension. In fact, set and dict are in C.
  4. Common wisdoms such as optimizing inner loops, or better flatten (unroll) the loop itself, using local instead global variables to take advantage of cache, are helpful but not by much in Python.
  5. Measurements are a must.
Quite a nice read. The comments are also very insightful.

No comments:

Post a Comment