Registry / testing / perflint

perflint

JSON →
library0.8.1pypypiunverified

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 perflint
INSTALL
IMPORT
SIG · PERFLINT
P
perflint
testingpythonv0.8.1
Install
2.7s avg
Import
Disk
26MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.8.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 26.9MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.7s · import 0.000s · 27MB
26MB installed
● package 26MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Perflint as Pylint Plugin
pylint your_module/ --load-plugins=perflint
from perflint import some_check
Perflint is not imported as a Python module in application code. It's loaded as a plugin for Pylint via the command line or configuration.

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.

import os def process_data(items): # W8202: Global name usage in a loop # os.environ is a global lookup; cache it outside the loop for performance. for item in items: value = os.environ.get(item, 'default') # This will trigger W8202 print(value) def unnecessary_list_cast_example(data): # W8101: Unnecessary use of list() on an already iterable type for x in list(data): # data is already iterable, no need for list() print(x) def incorrect_dict_iterator_example(dictionary): # W8102: Incorrect iterator method for dict for _, value in dictionary.items(): # If only values are needed, use .values() print(value) if __name__ == '__main__': my_items = ['HOME', 'PATH'] process_data(my_items) my_tuple = (1, 2, 3) unnecessary_list_cast_example(my_tuple) my_dict = {'a': 1, 'b': 2} incorrect_dict_iterator_example(my_dict)
Debug
Known issues
gotchaPerflint is currently an 'early beta' and may generate false positives, requiring careful review of its findings.
fix
Always manually verify reported performance anti-patterns before refactoring code based on Perflint warnings.
affects: 0.1.0 - 0.8.1
breakingUsing `try...except` blocks inside loops can have significant computational overhead, especially in Python versions prior to 3.11 (R8203).
fix
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.
affects: <=3.10
gotchaDotted imports (e.g., `os.path.exists`) inside loops can be inefficient because Python performs multiple lookups in each iteration (W8205).
fix
Import the specific function or attribute directly before the loop (e.g., `from os.path import exists`) to reduce lookup overhead.
affects: All versions
gotchaAccessing global variables within a tight loop can be slower than using local variables (W8202).
fix
Cache the global variable's value in a local variable outside the loop, then use the local variable inside the loop.
affects: All versions
Upgrade
Version history
0.8.1latest on PyPI · released Jan 10, 2024
Audit
Dependencies
pylintrequiredPerflint functions as a plugin for Pylint.
Agent activity
2 hits · last 30 days
node
2
Resources
perflint — pip install perflint · libregistry