[Python-Dev] On the METH_FASTCALL calling convention

Nathaniel Smith njs at pobox.com
Sat Jul 7 06:22:24 EDT 2018

On Sat, Jul 7, 2018 at 12:19 AM, Stefan Behnel <stefan_ml at behnel.de> wrote:
> Typically, it's calls with 1 to ~3 positional arguments that occur in
> performance critical situations. Often just one, rarely more, and zero
> arguments is a fast case anyway. Keyword arguments will always suffer some
> kind of penalty compared to positional arguments, regardless of how they
> are implemented (at runtime). But they can easily be avoided in many cases,
> and anyone designing a performance relevant API that *requires* keyword
> arguments deserves to have their code forked away from them. :)

In numpy we do sometimes hesitate to use kwargs, even when we
otherwise ought to, because of the slowdown they incur. You're right
that there's always going to be some overhead here, and I can't say
how important these kinds of optimizations are compared to other
things people could be spending their time on. But kwargs do improve
readability, and it's nice when we can make readable code fast, so
people aren't tempted to obfuscate things in the name of speed.


Nathaniel J. Smith -- https://vorpus.org

More information about the Python-Dev mailing list