开发者

Should one minify server code when it's in production? [closed]

开发者 https://www.devze.com 2023-03-23 02:39 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

When it comes to the frontend code you always minify it (remove white spaces, comments etc) in production.

Should one do the same with server code? I usually have a lot of comments in my server files. But I have never heard about people doing so.

Wouldn't the server run faster if the code was op开发者_如何学Gotimized in the same way?


You're not going to have any improvement as the whitespaces and all formatting are lost when your server side code is translated to machine code (or interpreted). It's also not sent over the wire, it's read from the local filesystem, so while having less characters would lead to a faster startup, it would not make any difference on the long run and the startup speed gain would be marginal (or even unnoticeable).

So, no, minifying your server side code is basically useless, worse, it's probably going to make stack traces completely useless, as there's going to be a lot of code in the same line (and not necessarily with the same formatting you used).


I think that minification has more to do with reducing bytes on the wire than it does runtime efficiency.


i do not believe this offers any benefit to server side code since the server evaluates the code and doesn't actually send it down. If you are looking to optimize production code you can look into setting up a compiler cache such as APC for PHP


The purpose of minification is: (1) to minimize the amount of bytes transferred over the network; and (2) to speed up parsing (by the browser).

The equivalent of minification on the server side is byte-code compilation. In Python you have "Compiled" Python (.pyc and .pyo) files, in PHP you have Zend Optimizer and PHP bytecode Compiler and in Perl, B::Bytecode

On the server size, there's no "transfer over the network", the (source) file is simply read from disk so the performance difference is much smaller in this regard; the main performance gain is from speeding up parsing.

0

精彩评论

暂无评论...
验证码 换一张
取 消