Here are the patterns the tool recognises, and how to fix them.


Slow Duplicate Checking

(Pattern name: overlapChecking)

You are using a slow way of duplicate checking between 2 lists. Use this instead.

String Manipulation


(Pattern name: plusEquals)

Joining strings can be very slow, even when the strings are small.

Slow Joining Examples

mystring += "other string"
string = string1 + string2

Fast Joining Examples

myvar = 2

string = "some variable: %s" % str(myvar)
myname = "Reece"
mylastname = "Dunham"

# .join is way faster then a lot of methods commonly used!
myfullname = " ".join([myname, mylastname])


Every time you import a module in Python, a process is run that essentially pulls the module in. The only problem with it is that it has to actually pull all the methods in, which can be time consuming. For example, here is the result of trying to import a few well known and widely used packages:

>>> import timeit
>>> timeit.timeit("import sys")
>>> timeit.timeit("import os")
>>> timeit.timeit("import six")
>>> timeit.timeit("import sys, os")
>>> timeit.timeit("import os, sys, six")

As you can see, just importing 3 packages can take a full second!

So when possible, you should limit the number of imports you have. Any file that has more then 15 will be flagged by Perf.

Last update: