Will commenting-out unused code give my page a performance boost in any way, shape, or form?
Okay so my situation at work is that I've written about 200 or so lines of additional functionality into an aspx page's code-behind that is currently not to be implemented. It is in a subroutine that handles an event that currently has zero chance of occurring.
Because this code is not being used, I've gotten curious. Should I comment out the subrou开发者_如何转开发tine that has zero chance of firing? Would it do anything to enhance the performance of the page or anything like that if I did indeed comment it out? Or could/should I just leave it as is? Thanks in advance.
A few comments:
- Performance is often quite unintuitive, there's no substitute for careful measurement.
- Any compiled code in your address space consumes resources. So there might be some overhead. But how much relative to everything else happening? My guess is very little or even negligible but see item 1.
- Unexpected things happen as applications scale, negligible things can become important when they are copied multiple times. So prefer to keep things tidy.
- If you are using a source code management system then simply delete the code, it's saved in the old versions in the repository. Keep your code tidy. Commented-out code scares the maintainer.
Its highly unlikely that you will measure any significant differences if you throw in a couple of unused methods. They probably will be weeded out as part of compiler optimizations and may not even have any object code generated.
But useless code commented or otherwise surely scares a lot (#4 djna above)
I have no reason to believe it will make any difference whatsoever.
The only time I think it would matter is if you had loads of commented out stuff in HTML or something that actually had to be processed or rendered.
Why don't you try logging the execution times of a routine that calls methods in the same file as the code both commented out and not commented out to test it?
if there is nothing that actually causes the code to be called, there is no need to comment it out.
Sure, it will be added into the compiled assembly, but it isn't going to cause any performance boost on the part of your web application.
精彩评论