Skip to content

Optimizing FOR_ITER bytecode #91432

@sweeneyde

Description

@sweeneyde

We can execute one less opcode in every iteration (except for the first) of every for-loop by changing from

    GET_ITER
top:
    FOR_ITER
    [body]
    JUMP_BACKWARDS(top)
cleanup:
end:

to

    GET_ITER
    JUMP_FORWARD(bottom)
body:
    [body]
bottom:
    FOR_END(body)
cleanup:
end:

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.11only security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy