3 ms·
Actually, 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
by rockybernstein 8y ago
Actually, 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.