Node.js console.log performance

前端 未结 4 525
无人及你
无人及你 2021-02-01 04:15

If your Node.js code is littered with console.log statements are you inviting performance issues? Is it worth debug/production toggling this on/off? I realized logging is import

4条回答
  •  抹茶落季
    2021-02-01 05:00

    console.log slows down chrome because it is actually interfacing with the DOM on every call. The entire inspect element system is actually just tons of DOM elements. When you call console.log in the browser it it having to append a new element to the console on every call.

    You can see how console.log is really just HTML by right clicking on an element in console and clicking inspect element. This will in fact open a new console inspecting an already existing console. :D

    If you are really that worried about performance you could always remove the console.log feature completely(not really advised because it could get confusing). You basically can noop the function in the browser or server side. No more console.log no more speed impact :D

    console.log=function(){};
    

提交回复
热议问题