Message 197848 - Python tracker (original) (raw)

[Senthil Kumaran]

I am unaware of the optimization technique you refer to as well, it will helpful if you could point to any resource.

It's an old trick since the very first Pythons: global lookups are much slower than local lookups (the difference between the LOAD_GLOBAL and LOAD_FAST opcodes in CPython). Putting:

 ..., _fast=slow, ...

in an argument list means we endure the slow lookup (of slow) only once, when the function is first defined. When the function is called, that binding is available via the local (much faster lookup) variable _fast.

Purely a speed trick, but can make a real difference in very heavily used functions.

And it's a Good Idea to put a leading underscore on such arguments. It's never intended that users pass values for them.