Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native - Does console.log() hurt performance when going to production?

I have a lot of console.log() in my app. Most of them are in catch blocks, so I can clearly see what went wrong when developing. Some are there to log the current time so I can check function execution times.

When deploying to production, those console.log() will run in the client's devices. Can I just leave them as they are? Will they hurt performance/memory or may cause some exception or unwanted behaviors?

like image 265
Yaron Levi Avatar asked Aug 27 '16 14:08

Yaron Levi


People also ask

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.

Does console log work in production?

Now you are rest assured your console. log(…) will work properly on your local or staging server but will not output anything on your production server. Comments, suggestions or corrections are welcome.

Does console log consume memory?

console. log() causes memory leaks but only when the console is opened. Normally users do not open the console. So it is totally safe to print any huge objects to the console.

Does console log work in React Native?

Writing to the logs in a React Native app works just like in the browser: use console. log , console.


2 Answers

From React Native docs:

Console.log statements

When running a bundled app, these statements can cause a big bottleneck in the JavaScript thread. This includes calls from debugging libraries such as redux-logger, so make sure to remove them before bundling.

So yeah.. I would remove them :)

The ones in your catch statements may be ok to leave in as they only fire if there's an issue (would rather grab more info on that than worry about the performance hit)

There's more performance tips on the react native docs here

like image 106
David Avatar answered Oct 13 '22 20:10

David


Is this good practice to disable all console.log statements in your entire app?

Any side effects?

At top of file: App.js include:

// To assign console.log to nothing   
if (!__DEV__) {
  console.log = () => {};
}
like image 39
Ed of the Mountain Avatar answered Oct 13 '22 21:10

Ed of the Mountain