Does variable name length matter for performance i

2019-04-24 16:40发布

I have been seen this Does variable name length matter for performance C#? topic and have same question about php.

My co-worker (Front-end) have been encoded everything like $o, $r, $x, $m, $c and motivated it best performance. I really very doubt about it and code became difficult to read.

  1. $o - object or obj
  2. $m - $model
  3. $r - $query_result or $result
  4. $x - $xml_node

Every thing look like

            if ( isset ( self::$o[ self::$x -> name ] ) ) :

            $c = 'ClassPrefix_' . self::$o[ self::$x -> name ];

            $o = new $c;

            self::$x -> read ( );

2条回答
Evening l夕情丶
2楼-- · 2019-04-24 17:06

Variable names exist more as a programmer aide - when a program or script is interpreted, these are converted into memory locations. Shorter variables will only negatively impact performance of the programmer(s) when modifying / debugging code in the future.

Obfuscation is a widely used technique that involves replacing variable names with single/multi-character variable names, but that is used in an attempt to make reverse engineering / lifting core technology from projects where the source code is readily available / easily extracted more difficult.

查看更多
唯我独甜
3楼-- · 2019-04-24 17:06

While it may save a byte here and a byte there, no, it does not matter one iota, and you will not see real memory or performance savings by using short variable names.

If you are really worried about memory use and performance, profile your code. xdebug and xhprof are great tools to get it done. You can even install xhprof on your production machines. Once you've actually measured your performance and memory use, then you can target the real problems in your code.

Also, make sure you're running 5.4, if you can. It introduces some huge improvements to both performance and memory use.

查看更多
登录 后发表回答