-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
PyCode_GetCode could be faster #93382
Copy link
Copy link
Closed
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
Metadata
Metadata
Assignees
Labels
3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
This potentially affects tools like coverage.py. It also means anything using
co_codein CPython frequently is significantly slower. Note that pre-3.11, most code would assume this operation is O(1), so it's probably called more often than we expect.We should lazily initialise a hidden
_co_codefield and cache it there. Currently it creates a fresh bytes object on eachco_codeaccess. This is at best O(n).