Skip to content

bpo-44525: Copy freevars in bytecode to allow calls to inner functions to be specialized#29595

Merged
markshannon merged 8 commits intopython:mainfrom
faster-cpython:copy-free-vars-in-bytecode
Nov 23, 2021
Merged

bpo-44525: Copy freevars in bytecode to allow calls to inner functions to be specialized#29595
markshannon merged 8 commits intopython:mainfrom
faster-cpython:copy-free-vars-in-bytecode

Conversation

@markshannon
Copy link
Member

@markshannon markshannon commented Nov 17, 2021

This should speedup calls to functions, by allowing us to specialize calls to functions with free variables without penalizing calls to other functions.

  • Calls to functions without freevars might be a tiny bit quicker as we don't need to check for freevars when initializing the locals.
  • Calls to functions with freevars should be faster, as they can now be specialized.

However, there is a bit of yak-shaving involved:

  1. It is necessary to keep a reference to the function in the frame. This is actually cheaper than before as it we now only need borrowed references to the builtins and globals, saving a few loads and stores.
  2. In order to do 1, we need to create a new function for eval and friends, rather than just passing a FrameDescriptor.

Although the speedup is probably not significant this is worthwhile as it makes more operations explicit in the bytecode which what we want when optimizing.

https://bugs.python.org/issue44525

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants