[Python-ideas] Ordering keyword dicts

Eric Snow ericsnowcurrently at gmail.com
Mon Jun 10 08:33:22 CEST 2013


On Jun 9, 2013 11:15 PM, "Nick Coghlan" <ncoghlan at gmail.com> wrote:
> Guido's speed concern is specifically with any approach which requires
> the calling code to *always* check callables to see whether they want
> an ordered dictionary or not. Before we proceed to considering more
> exotic design ideas that require an "ordered or not" decision at the
> call sites, this concern should be validated by someone trying it out
> and checking the macro benchmark suite for the consequences.
>
> This can be done without actually making it possible to define
> functions that require order preservation - since we're mostly
> interested in the performance consequences when such a flag *isn't*
> set on the callables, an extra redundant check against
> "PyCFunction_GET_FLAGS(func) & 0x8000" (for PyCFunction instances),
> falling back to something like "PyObject_GetAttrId(__name__)" (for
> everything else), for all code paths in ceval.c that lead to creation
> of a kwdict instance should suffice.
>
> It may be that the cost of the flag check is swamped by the cost of
> actually creating the keyword dictionary, in which case the runtime
> check would be a preferable design choice, since function *invocation*
> wouldn't need to change, only function declarations.

I'm actually doing some of this checking incidentally as part of testing my
OrderedDict implementation.  I'm using a decorator to set the flag.  Don't
have anything conclusive to say yet.

-eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130610/3e61b603/attachment.html>


More information about the Python-ideas mailing list