Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will console.log affect to async performance?

I know it's might be silly. But at least, I got this feeling many times.

Sometimes I'm trying to fix some bugs, mostly with Angular's $http request, callbacks or even with Node promise.

When things go wrong, I try to put some console.log to detect the code flow, and from that moment, (mostly) the bugs will disappear! It's not only happened to me.

So I think, somehow, console.log affect to the performance (make the program run a bit slower), and then, it makes the bugs gone!

enter image description here

I know I'm not the only one think this. Do you think it's possible? Or have you also meet this kind of issue before? please discuss!

like image 538
Huy Tran Avatar asked Feb 03 '16 06:02

Huy Tran


2 Answers

Certainly!

This is especially noticeable when logging many items in a loop, or when logging complex objects. Calls to console.log can be time consuming, and consequently, that delay can resolve some of your race conditions.

like image 87
David Hedlund Avatar answered Oct 16 '22 02:10

David Hedlund


JavaScript usually considered as single threaded. that why it is most likely any extra code row will effect the performance.

here is a great answer why it is not sure that it is :(

Is javascript guaranteed to be single-threaded?

Good Luck!

like image 40
TERMIN Avatar answered Oct 16 '22 03:10

TERMIN