Skip to content

Lower BEFORE_WITH and BEFORE_ASYNC_WITH to attribute lookups and calls. #120507

Closed
@markshannon

Description

@markshannon

With the JIT and better tier 2 optimizations, effective specialization is becoming more important that plain speed in tier 1.

BEFORE_WITH and BEFORE_ASYNC_WITH could be specialized, but they are bulky and won't optimize well in tier 2.
Instead, we should lower them to attribute lookups and calls which can then be optimized.
We should add a LOAD_SPECIAL instruction for loading dunder methods and replace BEFORE_WITH as follows:

    COPY 1
    LOAD_SPECIAL __enter__ + NULL|self
    SWAP 3
    LOAD_SPECIAL __exit__
    SWAP 3
    CALL 0

Likewise for BEFORE_ASYNC_WITH.

Even without any specialization of LOAD_SPECIAL, the CALL will be specialized and the JIT can eliminate the COPY and SWAPs.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions