[Python-Dev] Micro-optimizations by adding special-case bytecodes?

Antoine Pitrou solipsis at pitrou.net
Wed Jun 28 10:20:54 EDT 2017


On Wed, 28 Jun 2017 09:50:10 -0400
Ben Hoyt <benhoyt at gmail.com> wrote:
> I've now got a patch to add new COMPARE_IS_NONE and
> COMPARE_IS_NOT_NONE bytecodes to CPython to attempt to speed up the
> very common "is None" and "is not None" expressions. It's a very
> simple change overall. Here is my patch:
> https://gist.github.com/benhoyt/e5ba19afe7b869fd743c1c39fc2afdf8

I don't want to discourage you, but this is unlikely to produce
significant speedups on real-world code.  The simple reason is that
comparing to None is not a bottleneck for any real application --
comparing to None is probably damn fast compared to everything else
the real application does.

That said, it would be nice if you could get stable benchmark results
to validate that theory (or not!) ;-)

Regards

Antoine.



More information about the Python-Dev mailing list