3 ms·
It's a common joke to say that if you just shorter names in C, your program might run faster. It's not true of course, but it Python, it might. All those names
by sametmax 8y ago
It's a common joke to say that if you just shorter names in C, your program might run faster. It's not true of course, but it Python, it might. All those names are used in hash computations and look ups, and you may shave a few micro seconds if you make your program unmaintable.
- rockybernstein 8y agoActually, no, shortening names won't speed bytecode up in the way you seem to be suggesting. Variables "are" indexed by position in some arrays like co_varnames, co_names, co_const and so on. See for example https://docs.python.org/3.8/library/dis.html?highlight=co_names#opcode-LOAD_FAST https://docs.python.org/3.8/library/dis.html?highlight=co_na... There are maps in the code object that will turn the index back into a name, but that's only used when some sort of introspection occurs, such as you might find in a debugger or traceback. The names found in an "import" of course is a string so there might some small advantage there in a shorter name.
- sametmax 8y agoVariables are not the only names in a program. Attribute lookups do use a dictionary.