删除注释会提高代码性能吗?JavaScript [英] Does removing comments improve code performance? JavaScript
问题描述
从 JavaScript 代码中删除注释会提高性能吗?
Does removing comments from JavaScript code improve performance?
我意识到这不是很好的编程实践,因为注释是开发的内在组成部分.我只是想知道它们是否确实在编译过程中增加了一些开销.
I realize that this is not great programing practice as comments form an intrinsic part of development. I am just interested to know if they do in fact add some overhead during compilation.
推荐答案
无论是编译还是解释 JavaScript,编译器/解释器都需要查看该行,确定它是注释,然后继续(或查看某个区域)行).对于 Web 应用程序,还需要下载注释行.
Whether your compiling or interpreting your JavaScript, the compiler/interpreter needs to look at the line, decide it's a comment, and move on (or look at a region of the line). For web applications, the comment lines also need to be downloaded.
所以是的,有一些开销.
但是,我怀疑您能否找到一个真实的场景,其中差异很重要.
However, I doubt you could find a real-world scenario where that difference matters.
如果您正在编译代码,则开销仅在编译运行期间,而不是在后续执行期间.
If you are compiling your code, the overhead is only during the compile run, not during subsequent execution.
这篇关于删除注释会提高代码性能吗?JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!