[Python-Dev] cpython: Use cached builtins.

Nick Coghlan ncoghlan at gmail.com
Thu Oct 3 13:05:39 CEST 2013


On 3 Oct 2013 06:00, "Victor Stinner" <victor.stinner at gmail.com> wrote:
>
> I don't remember where, but I remember that I also saw things like
> "str=str, len=len, ...". So you keep the same name, but you use fast
> local lookups instead of slow builtin lookups.

functools uses the local binding trick in lru_cache as a speed hack (pretty
sure it uses an underscore prefix, though).

However lru_cache *is* likely to end up being speed critical *and* it's
binding local variables , so it's actually shifting a lot more work to
compile time than merely trading a builtin lookup for a global lookup does.

For most code though, introducing that kind of complexity isn't worth the
cost in readability.

Cheers,
Nick.

>
> Victor
>
> 2013/10/2 Antoine Pitrou <solipsis at pitrou.net>:
> > On Wed,  2 Oct 2013 18:16:48 +0200 (CEST)
> > serhiy.storchaka <python-checkins at python.org> wrote:
> >> http://hg.python.org/cpython/rev/d48ac94e365f
> >> changeset:   85931:d48ac94e365f
> >> user:        Serhiy Storchaka <storchaka at gmail.com>
> >> date:        Wed Oct 02 19:15:54 2013 +0300
> >> summary:
> >>   Use cached builtins.
> >
> > What's the point? I don't think it's a good idea to uglify the code if
> > there isn't a clear benefit.
> >
> > Regards
> >
> > Antoine.
> >
> >
> > _______________________________________________
> > Python-Dev mailing list
> > Python-Dev at python.org
> > https://mail.python.org/mailman/listinfo/python-dev
> > Unsubscribe:
https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
https://mail.python.org/mailman/options/python-dev/ncoghlan%40gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20131003/4cfffd87/attachment.html>


More information about the Python-Dev mailing list