[Python-ideas] Do we need non-heap types any more? (Was: Implicit submodule imports)

Andrew Barnert abarnert at yahoo.com
Sun Sep 28 20:50:36 CEST 2014


On Sep 28, 2014, at 9:44, Sturla Molden <sturla.molden at gmail.com> wrote:

> Andrew Barnert <abarnert at yahoo.com.dmarc.invalid>
> wrote:
> 
>> Well, there's obviously a non-zero performance cost to doing all this
>> stuff with all types. Of course there's also a non-zero cost to checking
>> the heap-type-ness of all types. And both costs may be so minimal they're
>> hard to even measure.
> 
> With branch prediction on a modern CPU an "if unlikely()" can probably push
> it down to inpunity. Both the Linux kernel and Cython does this liberally.

On what modern CPU does unlikely have any effect at all? x86 has an opcode to provide static branch prediction hints, but it's been a no-op since Core 2; ARM doesn't have one; I don't know about other instruction sets but I'd be surprised if they did.

And that's a good thing. If that macro still controlled branch prediction, using it would mean blowing away the entire pipeline on every use of a non-heap type. A modern CPU will use recent history to decide which branch is more likely, so whether your loop is using a heap type or a non-heap type, it won't mispredict anything after the first run through the loop.


More information about the Python-ideas mailing list