In the generated object code, sub and constants not actually used (as indicated by the IDE) are still included, or the compiler/optimizer prunes unused code?
The reasoning behind this question is the usage of common modules across different projects, where project A uses sub 1,2, and 3, while project B uses only sub 1.
I haven't tried this myself, but I imagine it would be possible to test easily by creating an unused sub with a variable containing a unique string. Then compile (with no obfuscation) to app, then decompile the apk and finally do a simple text search in the decompiled source.
Presence of the string could probably be considered a strong indication whether things are evicted or not?
B4A v3.80 adds support for conditional compilation. From Wikipedia: In computer programming, conditional compilation is compilation implementing methods which allow the compiler to produce differences in the executable produced controlled by parameters that are provided during compilation...
Granted, I know absolutely nothing about Java, but aren't there any Java compilation flags that makes Java strip out unused code? (...goes investigating on the net for five minutes...) Nope, seems there aren't any flags or anything like that, as best as I can tell. Which means that the suggestion by @rosippc64a is quite sufficient.
I'm also fairly certain that @Erel could say something with certainty here, he lives and breathes this stuff every day.
In the generated object code, sub and constants not actually used (as indicated by the IDE) are still included, or the compiler/optimizer prunes unused code?
Just for completeness, there is one edge case that I can think of that isn't related to preoptimization. I can very well see myself doing the mistake of having two subs like this:
B4X:
' The one used in production
Private Sub ConnectToServer
dim username as String = "myApp"
dim password as String = "kjdsfhsdkjfhsdkfj"
dim address as String = "32.43.54.118"
Connect(username, password, address)
End Sub
' The one used while testing
Private Sub ConnectToServerDISABLED
dim username as String = "myApp"
dim password as String = ""
dim address as String = "16.20.42.1"
Connect(username, password, address)
End Sub
And then just rename-flip them as I test things back and forth while developing. And just leaving the testing server sub in the code when compiling the release app, mistakenly thinking that it will be removed. Granted, I have not made this mistake, but before this thread I think it would be quite possible for me to make it. Good thread.