Spaces, line breaks, tabs ; are they affect server performance?

后端 未结 2 1487
抹茶落季
抹茶落季 2021-01-07 04:53

Spaces, line breaks, tabs ; are they affect server performance ?

I\'m in the road of learning PHP and before I go further with my current coding style, i want to ma

2条回答
  •  生来不讨喜
    2021-01-07 05:13

    No and yes (but mostly insignificant). Slightly different way thinking about the issue from @pst's answer (not even thinking about disk io) but same end result.

    Simplified php behind the scenes - PHP is compiled to bytecodes on runtime. During compile, all spaces and comments are filtered down/out among many other actions.

    Filtering out more whitespace from less is mostly insignificant compared with all the other actions.

    The compiled bytecodes are what actually gets run.

    But let's say you are running a major website, have 1000s of web servers and each php file is getting called millions of times a day. All those previously insignificant bits of time add up. But so does all the other stuff that the compiler is doing. At the point that this all becomes an issue for you, it's time to start looking into PHP caching/accelerators. (Or more likely long before this.)

    Basically, those cachers/accelerators cache the compiled bytecodes the first time they are produced after the files are modified. Subsequent calls to the same file skip the compiling phase and go right to the cached compiled bytecodes. At that stage all the whitespace no longer exists. So, it becomes a moot point because they only ever compile once.

提交回复
热议问题