简体   繁体   English

NodeJ中的注释会影响性能吗?

[英]Do comments in NodeJs affect performance?

I am in the process of having to refactor an entire NodeJs project which is quite large. 我正在重构一个非常大的整个NodeJs项目。 One of the biggest problems I'm facing is that my predecessor included literally no documentation. 我面临的最大问题之一是我的前任包括字面上没有文件。

I'm used to clientside js, where comments can be stripped via uglify (or similar) before deploying to a production environment. 我习惯于客户端js,在部署到生产环境之前,可以通过uglify(或类似的)删除注释。

Is there something similar for node, or how do people handle this? 节点有类似的东西,或者人们如何处理这个? Is the performance impact of comments negligible? 评论的绩效影响可以忽略不计吗?

Comments do not affect code performance in a significant way. 注释不会以显着的方式影响代码性能。 Neither in the in client nor in the server. 无论是在客户端还是在服务器中。

What happens in the client is that if you're including JavaScript with comments those lines are still being downloaded by the browser, without no extra benefit for the user. 在客户端中发生的事情是,如果您将JavaScript包含在评论中,那么这些行仍然会被浏览器下载,而对用户没有任何额外的好处。

In client side code, comments add to the file size that needs to be sent to the browser, so that is why tools at used to remove comments. 在客户端代码中,注释会添加到需要发送到浏览器的文件大小,这就是用于删除注释的工具的原因。 On the other hand, the comments in server side code doesn't make much difference. 另一方面,服务器端代码中的注释没有太大区别。

Comments do not affect performance in a significant matter. 评论不会影响重要事项的绩效。 How I understand it, the javascript program is being loaded into the memory. 我是如何理解的,javascript程序正被加载到内存中。 In this process the comments are being ignored and are not loaded into the memory. 在此过程中,注释将被忽略,并且不会加载到内存中。 Meaning that only during the loading of your application you could experience extremely minor increase of loading time while having a lot of comments. 这意味着只有在加载应用程序期间,您才能在获得大量注释的同时,轻松增加加载时间。 But this is negligible. 但这可以忽略不计。

Using uglify would not be necessary since users cannot read your NodeJS code. 由于用户无法读取您的NodeJS代码,因此无需使用uglify。 And it would make the newly refactored code less readable for you (which would be counterproductive). 它会使新重构的代码对你来说不那么可读(这会适得其反)。

Like Alberto and Konst are pointing out is that uglify can be used to reduce file size for downloading by the client. 就像Alberto和Konst指出的那样,uglify可用于减少客户端下载的文件大小。

Note: I do not know if i am exactly correct, please do correct me if i am wrong. 注意:我不知道我是否完全正确,如果我错了,请纠正我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM