Node.js console.log performance
console.log calls in nodejs are synchronous(!) and block the event loop. I just experienced that when I logged the results from executing (asynchronous) sql queries with pg. Logging only 20 items and their (few) properties decreased the performance from 3ms to 300ms on my local machine.
Edit:
console.log is synchronous and it is blocking the event loop
I think this is low hanging fruit, and will almost not give you any speed bump at all when you disable logging(if not used rigorously in critical parts). Probably the console.log is implemented in pure C. Also there are some modules available which can turn off logging in production, just as you can do with socket.io:
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(){};