Log.d And Impact On Performance
I'm not entirely sure about what I'm reading in the documentation. Is it ok to leave a bunch of log.d pieces of code scattered about, or should I comment them out so that they don'
Solution 1:
Log has impact on performance, so it's recommended that you comment it out or log with conditional statements.
For example
publicclassMyActivityextendsActivity {
// DebuggingprivatestaticfinalStringTAG="MyApp";
privatestaticfinalbooleanD=true;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(D) Log.e(TAG, "MyActivity.onCreate debug message");
}
Then in when you publish your release version just change "D" to false
Solution 2:
My solution:
- Add unguarded log statements wherever you like
- Strip them out for release builds
Solution 3:
Definitely comment them out. They add up quickly and could noticeably slow down your app, especially if you have them in loops.
Solution 4:
Simply use code guard methods.
if (Log.isLoggable(LOG_TAG, Log.DEBUG)) {
Log.d(LOG_TAG, "Your log here");
}
Solution 5:
Yes print, println, Log.d, Log.e and all similar methods affect performance.
The solution
create a class named C
classC{
publicstaticStringTAG="My_debug_tag";
publicstaticboolean isInTesting=true;
publicstaticvoidlog(String tag, String msg){
if(!isInTesting) return;
Log.d(tag==null?TAG:tag, msg);
}
}
and use these methods for all your logs, and when you are ready to generate final .apk/.aab just set isInTesting=false to disable all logs from this method.
Post a Comment for "Log.d And Impact On Performance"