DEV Community

Cover image for Gain performance by inline
Bigyan Thapa
Bigyan Thapa

Posted on

Gain performance by inline

Recently watched a video by Florina Muntenescu here, regarding Inline functions in Kotlin. Wanted to share something I learned here:

A function can be inlined with inline keyword. e.g.

inline fun foo(){
}

When a function is marked as inline it is compiled to the call site . This will decrease memory allocation especially when using lambda expressions in kotlin. If a function is not marked as inline , the compiler will create new function object for it. By inlining the function, compiler will copy the implementation to the call site avoiding the requirement to create new function objects. 

However, we should be careful when using inline functions. Inlining large functions increases the size of generated code.
For further reference please watch the video on the link.

Thanks!!

Top comments (0)