Mathematics, philosophy, code, travel and everything in between. More about me…

I write about

Speeding up Python’s Enum by 35%

I’ve been profiling a high-performance Python application and was surprised to see Python 3.4’s Enum spending nontrivial time on attribute lookups (expressions like MyEnum.SOME_MEMBER). It turns out these lookups can be sped up by 35% by removing two lines of code.

That code is verifying that the attribute being looked up is not a “dundered” name (__something__). Well, I can live without that check. Dropping it makes for a quick gain when you’re doing hundreds of lookups per second. Though, ditching the standard library implementation and writing a faster tailored solution might be the way to go here.

See the fastenum repository for test results and code.

September 15, MMXIV — Python.