Inline function
If you paid attention to our previous chapter, you will remember that we discussed Standard.kt file and functions. All those functions are inline. Inline function means replacing the body of the function at the time of building the file. It's not an actual function call.
Using higher-order functions (https://kotlinlang.org/docs/reference/lambdas.html) imposes certain runtime penalties—each function is an object, and it captures a closure, that is, those variables that are accessed in the body of the function. Memory allocations (both for function objects and classes) and virtual calls introduce runtime overhead.
But it appears that in many cases this kind of overhead can be eliminated by inlining the lambda expressions. The ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access