Does how you name a variable have any impact on the memory usage of an application?

前端 未结 7 1313
灰色年华
灰色年华 2021-02-20 09:05

Declaring a variable name, how much (if at all) impact does the length of its name have to the total memory of the application? Is there a maximum length anyway? Or are we free

7条回答
  •  我在风中等你
    2021-02-20 09:20

    In Python, the names appear to be collected into a number of simple tables; each name appears exactly once in each code object.The names have no impact on performance.

    For statistical purposes, I looked at a 20 line function that was a solution to Project Euler problem 15. This function created a 292-byte code object. It used 7 distinct names in the name table. You'd have to use 41-character variable names to double the size of the byte-code file.

    That would be the only impact -- insanely large names might slow down load time for your module.

提交回复
热议问题