Author gvanrossum
Recipients BTaskaya, Guido.van.Rossum, Johan Dahlin, Mark.Shannon, barry, bismatrimony, corona10, gvanrossum, methane, nascheme, pablogsal, yselivanov
Date 2021-01-30.05:39:42
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>

The loop overhead is presumably dramatic in that example. I think I measured a somewhat bigger speedup using timeit, which IIRC subtracts the cost of an empty loop. But you're right that 5% on a micro-benchmark is not very exciting.

I wonder if there are cases where the speedup is larger, e.g. in a class with __slots__ where the method is defined in a base class (also with __slots__). In that case LOAD_METHOD would require two dict lookups, both of which we'd avoid here.

This could be relevant if we had a hidden class mechanism (I'm playing with that but it's too soon to show anything). Let's keep your patch around for that.

Has anyone looked at storing the cache literally inline? If we had a way to rewrite bytecode that allowed us to move code (requiring us to fix up jumps) the cache data could be stored inline in the bytecode array (I guess that's why they call it "inline cache" :-). So e.g. LOAD_METHOD could have a layout like this:


This would avoid the pointer chasing needed to find the opcache struct, and increase memory locality. Obviously the bytecode would have to be copied to mutable memory.

We could even make it so that "LOAD_METHOD with opcache entry" is a new opcode, so there would be less overhead for unoptimized code (and for optimized code :-).

We'd have to do something funky for concurrent invocations of the same function (due to threading or recursion), but that can be dealt with; e.g., the frame could hold a pointer to the bytecode array in use.
Date User Action Args
2021-01-30 05:39:42gvanrossumsetrecipients: + gvanrossum, barry, nascheme, methane, Mark.Shannon, yselivanov, Guido.van.Rossum, corona10, pablogsal, Johan Dahlin, BTaskaya, bismatrimony
2021-01-30 05:39:42gvanrossumsetmessageid: <>
2021-01-30 05:39:42gvanrossumlinkissue42115 messages
2021-01-30 05:39:42gvanrossumcreate