DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
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)

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.