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

Brett Cannon brett at python.org
Wed Oct 21 20:43:07 CEST 2015


On Wed, 21 Oct 2015 at 10:31 Paul Moore <p.f.moore at gmail.com> wrote:

> On 21 October 2015 at 18:12, Brett Cannon <brett at python.org> wrote:
> > But as a starting point, getting some way to cheaply detect when the
> > built-ins have not been modified from what they are set to by default
> would
> > be nice to have.
>
> Would it be worth focusing on mechanisms like this, which would be of
> general use to various projects, and treating Victor's specific
> optimisation use case as simply that, a motivating example?


I think so.


> At least
> in the first instance - as Victor pointed out, previous attempts to
> introduce optimisations have always failed because it's not possible
> to switch off Python's dynamic nature. So maybe if we had tools which
> allowed code to more easily *detect* when Python's dynamic features
> have been used (or rather, when they have *not* been used) we'd be in
> a better position to develop optimisation strategies that know when
> they are appropriate?
>

Exactly, and especially if the check is cheap. After that you start to
potentially get into granularity, e.g. do you care if *any* built-in
changed or do you only care if a *specific* built-in changed, and how do
either approach affect performance? The trick is not breaking compatibility
and not hurting performance in the general case. But yes, knowing when the
uncommon case of overriding a built-in occurs would allow for a bunch of
optimization techniques from inlining to using a faster implementation that
is compatible with the standard built-in.

-Brett


>
> (Another example - Victor mentioned that CPython uses
> PyFunction_Check, which isn't friendly to function subclasses. A fix
> to allow function subclasses to work more seamlessly would be another
> useful general mechanism).
>
> Paul
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151021/e75aae5e/attachment.html>


More information about the Python-ideas mailing list