You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Specialize FOR_ITER for map() with a Python function #162463
for x in map(func, iterable) with a Python func makes a Python → C → Python round trip on every item: FOR_ITER calls map.__next__, which calls func through vectorcall and re-enters the interpreter. A FOR_ITER_MAP specialization can instead fetch the next item from the map's inner iterator and push the frame of func directly, the way FOR_ITER_GEN pushes the generator frame. The return value of func becomes the loop item.
The specialization applies when the iterator is an exact map object with a single iterable and its function is a plain Python function. Everything else keeps the current path.
A prototype (about 60 lines in bytecodes.c and specialize.c) gives 1.2–1.3x on such loops and comprehensions, with no change for C callables.
Activity