li'lfluf
11/22/2026, 12:12 AM"foo".startsWith("f")
while the following becomes true in bytecode:
("foo" as java.lang.String).startsWith("f")
I think I understand why from the perspective of R8, but isn’t this a bit of a problem for Kotlin? I imagine there may be quite a few methods that could be optimized but are not?Samyaraj Das
11/23/2026, 7:13 AMStringsKt.startsWith$default, while the Java cast calls String.startsWith directly. In my test, R8 reduced both methods to true.
My setup used the Kotlin 2.4.20 standard library and wasn’t an Android APK build, so it may differ from yours. Which Kotlin and R8/AGP versions are you using?li'lfluf
11/23/2026, 8:40 PMboolean kotlin.text.StringsKt__StringsJVMKt.startsWith(java.lang.String, java.lang.String, int, boolean) was not inlined into `boolean kotlin.text.StringsKt__StringsJVMKt.startsWith$default(java.lang.String, java.lang.String, int)`: not inlining due to code size heuristic (inlinee may have multiple callers and is not considered trivial).
(You can get the reason with a -whyareyounotinlining rule.)li'lfluf
11/23/2026, 8:47 PM-alwaysinline (unsupported but works), and for this method it saves me around 1KB for a 3MB app. Maybe not a big deal, but there are likely more methods like this that and the overall effect on the apk size might be significant. But maybe more importantly, this kind of a method is sometimes used with constant text, and if it can be optimized to true it can lead to further optimizations in the caller.Samyaraj Das
11/24/2026, 5:07 AM-alwaysinline in a production build given that it’s unsupported.