-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Optimizing FOR_ITER bytecode #91432
Copy link
Copy link
Closed
Labels
3.11only 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.11only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usagePerformance or resource usage
We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from
to
This was suggested by @markshannon here, but it appears to be similar in spirit to Loop Inversion.
There seems to be a small (on the order of 1%) benefit, but I imagine the benefit will be magnified after any specialization.