Skip to content

Add an external flag to interpreter frames #158572

Description

@kddnewton

Feature or enhancement

I would like to add an external flag to the _PyInterpreterFrame struct. This would be a single bit, bit-packed into the same uint8_t that the currently unused visited flag is already occupying.

When anything besides the VM pushes a frame onto the frame stack (for example, anyone using the long-blessed PEP 523 evaluators or writing JITs), oftentimes there is metadata associated with those frames that needs correlation. In order to make that correlation, we need to know if a frame is associated with an external source. There are a couple of ways to solve this, but every solution that doesn't involve storing something on the frame itself involves maintaining a separate data structure and mutating it on every activation. This becomes especially difficult when dealing with arbitrary frames, for example from the perspective of either GC or a profiler/debugger.

The ideal solution involves having a bit on the interpreter frame that indicates it's safe to read some other data structure containing the metadata. For example, we could stack allocate the metadata immediately before the interpreter frame, and this bit proves it's safe to read.

This should have zero impact on memory, since it's using an existing bit. It should also have zero impact on performance until the point that the visited flag is actually used, at which point it should be negligible since it will be one additional mask.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

cc @DinoV @markshannon

Linked PRs

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions