A third attempt at super().meth()
optimization via combined instructions
#239
Replies: 4 comments 2 replies
-
Note that there are no calls to |
Beta Was this translation helpful? Give feedback.
-
There are some super calls in deltablue, but they all pass the class and instance. |
Beta Was this translation helpful? Give feedback.
-
You can get around this by creating an adaptive form for the first instruction (already done!), then specializing into a superinstruction. |
Beta Was this translation helpful? Give feedback.
-
The problem with the static approach proposed in python/cpython#24936 is that it is bulky because it must handle both the slow and fast path. A specialized form only need include the happy path, so should be more compact at least. I note that |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently
super().meth()
creates the following bytecode:Past Optimization Attempts
The Cinder?(or Pyston?) team opened a PR against CPython to optimize this at the compiler level and emit super-specific bytecode. This was met with some opposition due to the compiler complexity introduced (it also special-cased
super
in the compiler, treating it almost like a keyword).I attempted a
LOAD_METHOD_SUPER
specialization, but it barely produced speedups (and also segfaults generously). The bulk of CPU time still went to the creation of a customsuper
object.Proposal (Attempt 3)
I propose we fuse the
CALL_NO_KW
+LOAD_METHOD
instruction using the runtime specializer. This combined instruction will then look like this:Benefits:
super()
object, which should be a huge speedup.super().meth()
lookup work with our pre-existing type method cache (MCACHE) in CPython. Currently everysuper()
object is newly allocated, so CPython's type method cache stores no information about method lookups on anysuper()
call.Cons:
I plan to implement this when I have the time to soon, unless there are major objections to this approach. Hopefully, this means that
super().meth()
calls will be near zero-cost (or at least as cheap as a normalself.meth()
lookup can be currently :).Beta Was this translation helpful? Give feedback.
All reactions