Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js console.log performance

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 important to prod in general - but I'm generally curious if the console output has a performance hit?

In Chrome it definitely seems to degrade performance if the console is open.

like image 786
j03m Avatar asked Jul 28 '11 02:07

j03m


People also ask

Does console log affect performance Nodejs?

It greatly effects performance. I just did a test with console. log with 60,000 keys in my GAMES object. Then, simply did a for in to check if a property exists while console logging the GAMES object before checking.

Does console log affect performance?

console. log by itself doesn't really impact performance in a way that you'll notice unless you bind it to a scroll / resize handler. These get called alot and if your browser has to send text to the console like 30/60x a second it can get ugly.


1 Answers

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.

like image 153
ha110_b1mm3lbahn Avatar answered Sep 22 '22 21:09

ha110_b1mm3lbahn