Re:Shrinking a Kotlin Binary by 99.2%
by brabel on Wednesday August 26, 2020 @02:47AM
(#24279840)
If you're going to get rid of all your Kotlin std lib usages by explicitly replacing them, after inspecting the actual class files generated by the compiler, with standard Java methods (and hope that no future change will re-introduce them) and you care so much about the size of your jars, I would say you're better off simply going back to Java, perhaps using the very latest version (since you're willing to use Kotlin that shouldn't be a problem) which has lots of niceties and to me, at least, looks a lot better than using Kotlin with these kinds of hacks. Add a nullability static analysis check and you're gold.
[ Parent
| on HN ]
The takeaway is "make sure you use a tool like R8 or ProGuard to remove unused code paths". That's where most of the savings came from, and the advice applies to Java projects as well.
But true, if you care about every last byte, you might use Java instead. You might also use another language entirely.
Haven't watched it yet, but looks like the author gave a talk recently about differences between Kotlin and the latest Java: https://jakewharton.com/whats-new-in-java-19-the-end-of-kotl...
Re:Shrinking a Kotlin Binary by 99.2%
by Jake_Wharton on Wednesday August 26, 2020 @11:27AM
(#24283307)
The final section of the post was a Java port and size comparison. It also noted that while it was smaller, I simply don't want to use Java and the minute any external dependency is added (such as for CLI parsing) I'm right back to needing R8 for minifying.
I removed that part since the post was long enough.
At that point, why not use Rust or Go or D or whatever with significantly smaller binary sizes and (un-optimized) faster speeds.
Re:Shrinking a Kotlin Binary by 99.2%
by Jake_Wharton on Wednesday August 26, 2020 @11:30AM
(#24283340)
The goal here was to get the binary size to be small enough, not the smallest it could possibly be. The tool was written in 2 hours because I used a language I was proficient in. While I love me some Rust it would easily double if not triple the time it would take me to build the thing in the first place
Re:Shrinking a Kotlin Binary by 99.2%
by tasubotadas on Wednesday August 26, 2020 @03:50PM
(#24286500)
If that's the real Jake Wharton, I have to say I am a big fan of the tools/libs (and their quality) you wrote for Android. They were especially useful 7-5 years ago, when the "official" libs were pathetically crappy :).
Re:Shrinking a Kotlin Binary by 99.2%
by tasubotadas on Wednesday August 26, 2020 @06:15AM
(#24281025)
Not on Android
On Android you are stuck with Java8 so GP's point melts away.
C or C++ then
Re:Shrinking a Kotlin Binary by 99.2%
by FlyingSnake on Wednesday August 26, 2020 @07:25AM
(#24281403)
Rust has first class support for Android.
Cool, so I can start a new service and bind activities to it from Rust without having to deal with a nasty JNI or an unstable ABI that changes under my feet?
That's hardly the full story. Rust provides all the support it is able to provide for Android, yes. But it still relies on the NDK and has to sit behind a JNI layer. A "Kotlin vs Rust" comparison for Android is apples and oranges.
What do you mean by "first class support" here? Some quick searches doesn't give me results that goes in this sense (nothing official from the rust and/or android projects).
I love D but it's ecosystem just isn't there. If you need the jvm ecosystem you're probably better off with Graal.
Re:Shrinking a Kotlin Binary by 99.2%
by saagarjha on Wednesday August 26, 2020 @05:49AM
(#24280881)
Those compile to native.
Disagree. A lot of the value of Kotlin is stuff that doesn't even make it into the binary, like scope functions.
Re:Shrinking a Kotlin Binary by 99.2%
by MaxBarraclough on Wednesday August 26, 2020 @05:23AM
(#24280687)
Doesn't it make more sense to look at this work as proof-of-concept for what the Kotlin compiler could do automatically?
If you have used Kotlin you would have known that no sane person wants to go back to Java after being exposed to Kotlin.
What a silly way to look at things.
If it matters, I've been programming more in Kotlin than in Java nowadays, and I have no trouble at all going back to Java... it's a nice language for its age and it gets the job done robustly. I even prefer Java for small applications that I want to distribute to users as small jars, for example. Kotlin has some nice benefits, but it's not a panacea that makes Java irrelevant - it actually strengthens the Java ecosystem in my opinion - it's another tool for the Java developer to use when appropriate.