Marc Knaup
11/24/2020, 11:30 PMx.toString(). Use "$x". The former cannot be optimized by Terser.
• Avoid Number. Cannot be optimized by Terser.
• Avoid String.isEmpty() and String.isNotEmpty(). Unnecessarily imports CharSequence code. Use == "" and != "".
• Avoid StringBuilder. Imports heaps of code. I’ve made a cheap alternative: https://gist.github.com/fluidsonic/473758c30dd084042905e77c5ebd0374
• Avoid Long if possible. Uses a custom JS class fo Kotlin and cannot be optimized by Terser.
• Avoid `print`/`println`. Imports heaps of code. Use console.log. But even the latter isn’t efficiently implemented.
• Prefer unsafeCast<Foo>() over as Foo when you’re certain of the type. The latter adds overhead and imports more code from stdlib.
• Use external when possible to reduce amount of classes & interfaces.ankushg
11/25/2020, 12:20 AMgildor
11/25/2020, 5:04 AMcrowdsourced custom ktlint or detekt rulesetat least some should be just a compiler optimization
hallvard
11/25/2020, 9:14 AMRobert Jaros
11/25/2020, 5:07 PMMarc Knaup
11/25/2020, 10:54 PMRobert Jaros
11/25/2020, 11:03 PMtoString and as) the large KVision app bundle size changed:
- from 3734268 to 3733838 (for legacy compiler) (-0,01%)
- from 5322345 to 5319680 (for IR compiler) (-0,05%)
😉
So no miracles here but it does work. And the legacy compiler is better optimized as should be expected.Robert Jaros
11/25/2020, 11:05 PMRobert Jaros
11/25/2020, 11:24 PMMarc Knaup
11/26/2020, 1:33 AMexternal and inline excessively.Marc Knaup
11/26/2020, 1:33 AMMarc Knaup
11/26/2020, 1:35 AMMarc Knaup
11/26/2020, 1:41 AMMarc Knaup
11/30/2020, 10:42 AMdata class as it will add lots of implementations that you likely never use but that increase bundle size.
E.g. if you only need equals() you don’t want hashCode(), componentX() and esp. toString() to be generated.
Likely cannot be removed by the minimizer.