简体   繁体   English

是否有太多console.logs影响单页应用程序/选项卡的内存和性能?

[英]Do too many console.logs affect Single Page application's/tab's memory and performance?

I am building a single page web application(SPA). 我正在构建一个单页Web应用程序(SPA)。 My team has an extensive habit of using console.log's for debugging. 我的团队习惯于使用console.log进行调试。 Since we work in an Agile project, our production code tends to accidentally carry forward some of these console.logs. 由于我们在敏捷项目中工作,因此我们的生产代码往往会意外地继承其中的一些console.logs。

As a result of it, the App being an SPA, after a few minutes of transactions we end up with a few Hundred logs, in case we haven't hit refresh(F5). 结果,该应用程序成为SPA,在经过几分钟的交易后,如果我们没有刷新(F5),我们最终会收到几百个日志。

Is the number of memory bytes allocated per browser tab limited and do these console log's eat into the memory otherwise allocated for the application? 是否限制了每个浏览器选项卡分配的内存字节数,并且这些控制台日志是否占用了为应用程序分配的内存?

Does this significantly affect the SPA's performance? 这是否会严重影响SPA的性能?

If yes, 如是,

Is doing this(below code) at the application scope level a good solution ? 在应用程序范围级别执行此操作(在代码下方)是否是一个好的解决方案?

setInterval(function() {
    console.clear();
}, 30000);

Also for Angular Js : Does the $log service provide it's equivalent for console.clear()? 同样对于Angular Js:$ log服务是否提供与console.clear()等效的服务?

I personally wouldn't worry about the performance issue, but I'd suggest being able to turn on and off the console.log in production if it is a viable option: 我个人不会担心性能问题,但是我建议能够打开和关闭console.log(如果可行)在生产环境中登录:

var loggerPlaceholder = console.log;
function turnOfLog(){
    console.log = function (){}
}
function turnOnLog(){
    console.log = loggerPlaceholder
}
if(isProduction()){
    turnOfLog();
}

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

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