Perflint is an extension for Pylint that identifies performance anti-patterns in Python code, helping developers optimize their applications by flagging common inefficiencies. It is currently in early beta, version 0.8.1, and may produce false positives. The project is actively maintained with a focus on enhancing code performance through static analysis.
pip install perflintVerified import paths — ran on the pinned version, not inferred.
Save the code above as `my_module.py`. Then run Perflint as a Pylint plugin. It will highlight performance anti-patterns like global lookups in loops, unnecessary list casting, and inefficient dictionary iteration.
Always manually verify reported performance anti-patterns before refactoring code based on Perflint warnings.
Refactor code to place the entire loop within a single `try` block, or move exception handling outside the loop if possible, to avoid per-iteration overhead.
Import the specific function or attribute directly before the loop (e.g., `from os.path import exists`) to reduce lookup overhead.
Cache the global variable's value in a local variable outside the loop, then use the local variable inside the loop.