Android Question log statement Performance

Chris Lee

Member
Licensed User
Still learning B4a but my app development is progressing well.

The log method is very useful but can slow execution.

I notice when running in release mode the logs are still output.

Will the logs get stripped out when I create an APK or will they stick around slowing things down?

Should I be using the conditional compilation feature to strip them out or is this unnecessary?
 

mangojack

Expert
Licensed User
Longtime User
I found nothing and cannot comment on Logs /Performance .. but it was just natural to rem Log lines prior to release.
I don't think they are stripped/removed prior to compile.

I did find a simple suggestion from @Erel which I never thought to do .... o_O

You can use Find & Replace tool to replace: Log( with 'Log(
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Or my method of madness...

Add this to a module.

B4X:
Public Sub debugLog(s As String)
    #If Debug
    Log(s)
    #End If
End Sub


My old routine:
B4X:
' Code module
Public LogOn As Boolean = True


Public Sub MyLog(Msg As String, UseLogColor As Boolean, Col As Int)
    If LogOn Then
        If UseLogColor Then
            LogColor(Msg, Col)
        Else
            Log(Msg)
        End If
    End If
End Sub

"old" also because I don't like that UseLogColor, it would be better to check if Col (which should be named Color) is null.


Anyway, the "idea" is the same of yours ;)
 
Upvote 0

Chris Lee

Member
Licensed User
Log will not affect the performance of your program unless you call it from a very tight loop.

I do have tight loops, so yes performance is impacted.
I don't really need them all the time though only when tracking obscure bugs. The commenting out idea is good. I thought about the separate subs suggested by others, but it still means a call to an empty sub routine.

I'm a bit obsessional at times about maximising performance. My main question was if the log statements still reside in the final APK. I don't think that question was definitively answered yet?
 
Upvote 0
Top