Skip to content

GH-128375: Better instrument for FOR_ITER#128445

Merged
markshannon merged 9 commits intopython:mainfrom
faster-cpython:better-instrument-for-iter
Jan 6, 2025
Merged

GH-128375: Better instrument for FOR_ITER#128445
markshannon merged 9 commits intopython:mainfrom
faster-cpython:better-instrument-for-iter

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Jan 3, 2025

This PR:

  • Changes the POP_TOP and the end of a for loop to POP_ITER (it pops the iterator)
  • Removes the NOT_TAKEN following FOR_ITER and instruments the FOR_ITER and POP_ITER instead
  • Fixes handling of EXTENDED_ARGS in co_branches().

The last one isn't strictly related to the issue, but came up while fixing the main issue.

Changing the instrumentation pattern has two effects:

  • For uninstrumented code, there is one less instruction dispatch (the NOT_TAKEN) per iteration, at the cost of one additional dispatch when the loop is exited.
  • For instrumented code, once the non-exit branch is DISABLEd, the FOR_ITER can be specialized and jitted.

Performance is neutral on the standard benchmarks for tier1, as expected.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants