bpo-43563 : Introduce dedicated opcodes for super calls by vladima · Pull Request #24936 · python/cpython (original) (raw)

I'm interested to see how this compares with adaptive specialization of PEP 659.

The expression super().attr compiles with this PR as:

          LOAD_DEREF               0 (__class__)
          LOAD_FAST                  0 (self)
          LOAD_ATTR_SUPER   1 ((1, True))

on main this compiles as:

         CALL_FUNCTION            0
         LOAD_ATTR                1 (attr)

So main has a (small) advantage in dispatching.
The question is, can a specialized form of CALL_FUNCTION 0; LOAD_ATTR match the custom opcodes.

Assuming we specialize both CALL_FUNCTION and LOAD_ATTR I think it can.
There will be the overhead of creating the super() object, but the specializer has more context than the static compiler and should be able to do a much better job on the attribute lookup.