문제

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 ( );
도움이 되었습니까?

해결책

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.

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top