[Python-ideas] Add specialized bytecode with guards to functions

Antoine Pitrou antoine at python.org
Thu Oct 22 19:33:26 CEST 2015


Brett Cannon <brett at ...> writes:
> 
> I'm not sure if Antoine was truly proposing adding version number
> support to all dicts, but I know I wasn't.

I am.  An empty dict is currently 288 bytes on 64-bit Linux.
Even an empty dict with key sharing (e.g. an instance dict, which
would be versioned anyway in your proposal) is 96 bytes long.
Adding a size_t-sized field would not make a significant difference
in memory consumption, and is probably much simpler than
ensuring you use the right dict subtype at each place,
add some type-checking to all PyDict concrete APIs, etc.

And incrementing the version number is cheaper if you don't have
a conditional branch based on whether the dict is a versioned or
non-versioned dict.

Regards

Antoine.




More information about the Python-ideas mailing list