Skip to content

Proposal for modified frame layout in 3.13 #657

Open
@Fidget-Spinner

Description

@Fidget-Spinner

I've decided to drop the plan of true function inlining for 3.13. The main problem is that debuggers use frame.f_locals modifications to work, which would break my current inlining plan.

Instead, I have another proposal that gets most of the frame inlining benefits, without the reconstruction requirements. This involves changing the frame layout slightly

image

The After layout has the following benefits:

  1. Reduced overhead via interleaved stack and locals. No copying of arguments at all for most tier 1 specialisations and simple function calls. The old frame's stack becomes the new frame's locals.
  2. Makes frame inlining easier in the future, as no copying during reconstruction is needed now.
  3. Makes the "hot" (commonly accessed) parts of the frame smaller, likely fitting better in cache.
  4. No complex reconstruction needed for sys._getframe.

There are some cons:

  1. Worse locality of data for cold fields in frame. Things like globals, builtins, code object, code attribute names, and constants are now a separate memory cache line than the frame's localsplus. I don't think this is a con with though (in fact, this is a plus). Those fields are rarely used once globals get promoted to constants, and all constants become inlined loads. We already rarely use attribute names already in tier 1 as specialisation doesn't use it. Making localsplus fit in a cache line is better.
  2. One extra local variable needed in eval frame to hold reference to new localsplus to avoid one more pointer indirection in load and store fast. Not sure if this will affect register pressure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions