13

Does having a lot of white space between chunks of code and empty lines in code slow down the performance of the application?

I have a tendency to space apart my code quite a bit, and I am wondering if it affects it negatively. Also, I have a lot of commented code that I commented out when I made changes, although I keep it around in case I ever have to go back to the old way. What are some other tips that could speed up performance?

4

5 回答 5

26

No performance degradation at all. Comments are not parsed by the compiler, they are usually removed in the lexical analysis.

于 2012-09-07T19:28:56.763 回答
15

Comments and whitespace have absolutely no effect.

Commented-out code should be removed however because it's "messy".

Keep your code in source control so you have version history, and never lose any historical changes.

Don't worry about optimization and speed until you notice your code being slow. Then you profile code, measure, compare, time, etc to determine where bottlenecks are, and what the cause is.

于 2012-09-07T19:29:23.263 回答
7

However its worth mentioning, in web envirnoment when you are NOT using a complied version of project then it matters, say you have 10,000 lines of comments/code in HTML/Css/Javascript then your browser will still download the chunk of data from webserver to your browser.

于 2012-09-07T21:16:24.677 回答
2

Comments and whitespaces are not not compiled by any compiler and are ignored, so these two have no effect on performance. But in web technologies like HTML, CSS and JS, it can have effect on the file download because comments and whitespaces increases file size, and hence the webpage loading speed may degrade.

So it is best practice to keep your code as much clean as possible, and use a source control system like git to manage your code. Also, before the final production of your code, it is best practice to remove all unnecessary comments and whitespaces and old unused chunks of code.

于 2015-08-25T20:12:32.680 回答
-1

No performance drops at all as its never compiled so no bit of that whitespace is compiled in to machine code and stufff

于 2022-01-25T17:43:19.117 回答