{"id":9173,"library":"perflint","title":"Perflint: Pylint Extension for Performance Anti-patterns","description":"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.","status":"active","version":"0.8.1","language":"python","source_language":"en","source_url":"https://github.com/tonybaloney/perflint","tags":["linter","pylint-extension","performance-optimization","static-analysis","developer-tool"],"install":[{"cmd":"pip install perflint","lang":"bash","label":"Install Perflint"}],"dependencies":[{"reason":"Perflint functions as a plugin for Pylint.","package":"pylint","optional":false}],"imports":[{"note":"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.","wrong":"from perflint import some_check","symbol":"Perflint as Pylint Plugin","correct":"pylint your_module/ --load-plugins=perflint"}],"quickstart":{"code":"import os\n\ndef process_data(items):\n    # W8202: Global name usage in a loop\n    # os.environ is a global lookup; cache it outside the loop for performance.\n    for item in items:\n        value = os.environ.get(item, 'default') # This will trigger W8202\n        print(value)\n\ndef unnecessary_list_cast_example(data):\n    # W8101: Unnecessary use of list() on an already iterable type\n    for x in list(data): # data is already iterable, no need for list()\n        print(x)\n\ndef incorrect_dict_iterator_example(dictionary):\n    # W8102: Incorrect iterator method for dict\n    for _, value in dictionary.items(): # If only values are needed, use .values()\n        print(value)\n\nif __name__ == '__main__':\n    my_items = ['HOME', 'PATH']\n    process_data(my_items)\n    my_tuple = (1, 2, 3)\n    unnecessary_list_cast_example(my_tuple)\n    my_dict = {'a': 1, 'b': 2}\n    incorrect_dict_iterator_example(my_dict)\n","lang":"python","description":"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."},"warnings":[{"fix":"Always manually verify reported performance anti-patterns before refactoring code based on Perflint warnings.","message":"Perflint is currently an 'early beta' and may generate false positives, requiring careful review of its findings.","severity":"gotcha","affected_versions":"0.1.0 - 0.8.1"},{"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.","message":"Using `try...except` blocks inside loops can have significant computational overhead, especially in Python versions prior to 3.11 (R8203).","severity":"breaking","affected_versions":"<=3.10"},{"fix":"Import the specific function or attribute directly before the loop (e.g., `from os.path import exists`) to reduce lookup overhead.","message":"Dotted imports (e.g., `os.path.exists`) inside loops can be inefficient because Python performs multiple lookups in each iteration (W8205).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Cache the global variable's value in a local variable outside the loop, then use the local variable inside the loop.","message":"Accessing global variables within a tight loop can be slower than using local variables (W8202).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"search_vec":"'0.8.1':40 'activ':49 'analysi':60,70 'anti':7,19 'anti-pattern':6,18 'applic':28 'beta':38 'code':23,56 'common':31 'current':35 'develop':25,72 'developer-tool':71 'earli':37 'enhanc':55 'extens':3,12,64 'fals':44 'flag':30 'focus':53 'help':24 'identifi':16 'ineffici':32 'linter':61 'maintain':50 'may':42 'optim':26,67 'pattern':8,20 'perflint':1,9 'perform':5,17,57,66 'performance-optim':65 'posit':45 'produc':43 'project':47 'pylint':2,14,63 'pylint-extens':62 'python':22 'static':59,69 'static-analysi':68 'tool':73 'version':39","created_at":"2026-04-16T18:48:50.723485+00:00","updated_at":"2026-04-16T18:48:50.723485+00:00","problems":{"verify_error":"no import statement found"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.8.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/tonybaloney/perflint","docs":null,"changelog":null,"pypi":"https://pypi.org/project/perflint/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"skip","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-05","install_tag":null}}