4 ms·
Some people still care about efficiency!
by llamaInSouth 3y ago
Some people still care about efficiency!
- tadfisher 3y agoContrary to popular belief, Java (well, Android) apps can be quite small if you have no external dependencies and minimal graphical resources. Once you depend on something like Jetpack Compose, you're pulling in about a hundred libraries and adding a few MB before minifying.
- superb_dev 3y agoIs minifying a concern in the Java world?
- chris37879 3y agoYup! It's a major step in building any Java application. Things like stripping symbol names, removing unused APIs, and processing non-java assets like images. For Android applications Gradle handles this by invoking some Android specific utilities alongside the java ones, but there's tons of build tools out there for Java that handle doing these things for everything from Blu-Rays to web apps.
- pjmlp 3y agoNot any Java application, only on Android and embedded. I never ever saw anyone doing it for desktop or server applications.
- contrarian1234 3y agoUnfortunately you can't treeshake a language that supports reflections. So it's not like a C++ program where unused parts get dropped. You can manually remove dependencies or.. I think in the Android world you specify what classes can be reflected on and then strip unused code with Proguard (though I could never get it working with Clojure) Would love to be corrected if I got any of it wrong
- koolba 3y ago> Unfortunately you can't treeshake a language that supports reflections. I’m pretty sure that’s exactly what the Google Closure Compiler does: https://developers.google.com/closure/compiler/docs/limitations https://developers.google.com/closure/compiler/docs/limitati... Though it has a ton of restrictions on how you write code and how you can use reflection.
- izacus 3y agoI'm afraid you did get it wrong - it's very standard to do that on all Android apps. The part that you missed is that reflection is rarely used in production apps (partially because for a long time, reflection was VERY expensive on Dalvik/ART runtimes) and can be easily handled by configuration for minifier/optimizer to explicitly keep code. Even C++ you mention does that - you have explicit __attribute__ calls to avoid linker from dropping code you want to keep for reflection purposes.
- meindnoch 3y ago>Unfortunately you can't treeshake a language that supports reflections. Like JavaScript?
- gkbrk 3y agoYes, you can't treeshake Javascript. You can treeshake a subset of Javascript. If you are limiting tooling to subsets, you can also compile subsets of Python or Javascript to machine code.
- pjmlp 3y agoYou surely can, it is a thing since Smalltalk and Common Lisp images. On Java's case, all AOT toolchains and embedded deployment workflows have supported similar capabilities.
- izacus 3y agoYes, it's enabled by default even in tutorial Android apps - Proguard was the tool used in olden days and has now been replaced by Google developed R8 optimizer/minifier.
- tauntz 3y agoYup! Most used to rely on Proguard but nowadays, Android ships an alternative called R8: https://developer.android.com/build/shrink-code https://developer.android.com/build/shrink-code
- vbezhenar 3y agoIs it even supported way to write Android apps without compat libs? I tried to do that, and struggled. I hate dependencies and prefer to avoid them, however with Android that seems almost unavoidable (or requires expert knowledge of quirks of different Android versions, I guess).
- maxhille 3y agoAppCompat/JetPack don't do anything magical - they are just regular open source libraries. If your app wants to use features which behave differently depending on the OS version, you have to if/else over the OS version. Also, note that the platform's Fragment implementation is deprecated and you might miss ViewModel.
- izacus 3y agoYes, after all, the Compat libs themselves need to talk to OS. But there's a reason why you were struggling - those libs have code that handles changes of API between different OS versions and there's been many of those during 14 major Android releases. Patching up those differences is after all the primary purpose of compat libs.
- wiseowise 3y agoIf you target latest OS - yes.
- grishka 3y agoMastodon app is built like that, the release apk is around 3 Mb, ~half of which is resources: https://github.com/mastodon/mastodon-android https://github.com/mastodon/mastodon-android Though it's not without compromises — because of Google's stupid policy that "nothing goes into the system unless it needs direct access to privileged or private system components", RecyclerView, ViewPager, and some other basic UI components are still AndroidX libraries that depend on AppCompat for no good reason. I had to fork them to rid them of that dependency: https://github.com/grishka/LiteX https://github.com/grishka/LiteX Is this a supported thing to do? No. Do I care about it being unsupported? Also no.
- 3y ago