Inline functions – Kotlin Vocabulary

Improve your app by saving some extra object allocations with inline functions!

Stay tuned to see what happens when you pass lambda functions as parameters, what inline does under the hood, and what you should be aware of when working with inline functions.

#KotlinVocabulary playlist →
Subscribe to Android Developers →

#Kotlin #AndroidDev #Featured

Similar Posts

29 thoughts on “Inline functions – Kotlin Vocabulary
  1. Kotlin crew has invented the ugly fix on what should work under the hood and continue extending the set of operators saying: "Kotlin is so idiomatic language". As an application developer I should think about Business Rules instead of: "Inline or not inline"? For me the whole picture looks like the following way: "I shoot my leg and lets make a party it is so cool" – No, guys -> its better to go to the hospital. The next step is to add C++ pointers and start allocate/deallocate objects manually saying it's so powerful and provides a lot of flexibility – joke. I've seen a lot of projects and I would say there is no consistency between them, because on trivial tasks each developer wants to demonstrate how does he know Kotlin and uses all his knowledge to make simple solution really complex and thats a real pain for those who will inherit the project and those who will join. That's a real shame. On the other hand Coroutines is a big win and thank you for that.

  2. Using inline function everywhere does not improve performance, but on the contrary, decreases it because JVM inlining is better than manual inlining. Also, using inline everywhere significantly bloats the bytecode because it creates a copy of the code for each call. So please, PLEASE, do not recommend using inlines for optimizations. And it definitely should not be ever used in large functions. Performance optimizations like that should not ever be used without need and without profiler measurements.

  3. This is nice and all, but I find myself missing how the ins and outs of the compiler work and I don't really understand some stuff about object creation. Therefore, I miss the problem inline functions are trying to solve… 😐

  4. I wrote exactly the same method in Kotlin 1.3.50 and 1.3.72. The decompiled java class is different. It uses an interface and an invoke method. Also, by using the inline keyword, there is no difference in the decompiled java class because of using that interface. Even, there is no IDE guidance to remove it

  5. So would it be accurate to say that the trade off of using the inline keyword is between performance and compiled code size? Inlining your functions can increase performance as the lambdas don't need to be instantiated as objects at runtime, but the size of your inlined function and the number of places you're using it both contribute to increasing the total size of your compiled code?

  6. If the rule is that simple (small functions which take a lambda, but don't pass or store it), why can't the Kotlin compiler decide by itself whether to inline a function or not?

  7. 2:34 You say it's not recommended to inline a function that doesn't have any function as parameter, but then on 2:52 you show so many functions that are inlined even though they don't have a function as parameter…
    What is going on?

  8. Oh yeah, there are nothing was said about reified types and crossinline: the first – it’s compile-time known generic type, using in most cases as “Class” type replacement, so convenient, the second one used to pass inlined blocks to another , new created objects inside of function (for example, pass block to new Runnable instance inside function)

  9. I don’t understand people, which don’t use Kotlin in their projects in 2020: come on, guys, Kotlin is official Android development language already for more than 2 years. Also, it’s pretty more beautiful, more convenient, than Java. You just need to exit from your “comfort zone”)

  10. Google does not need Kotlin. Google needs IntelliJ for Android Studio. But the point is that both Kotlin and IntelliJ are the products of the same company…

  11. Good video, great demo of the Kotlin <-> Kotlin bytecode <-> Java decompiled code, nice editing work too! Would be nice to also see `crossinline` for lambdas that are invoked inside another lambda

  12. I will start using kotlin as soon as my project is done but honestly apart from kotlin UI and soon being able to use it to create swift code I don't see the appeal reminds me more of JavaScript and I don't particularly like it

Leave a Reply

Your email address will not be published. Required fields are marked *