Sobes.tech
Junior — Middle

Is it possible to declare all functions as inline in a program?

sobes.tech AI

Answer from AI

Declaring all functions as inline is not recommended and often pointless.

inline is a hint to the compiler that the function body should be inserted at the call site to avoid the overhead of a function call. This can improve performance for very short and frequently called functions.

However:

  • Large functions declared inline increase the size of the compiled code (code bloat).
  • The compiler may ignore inline if it deems it inefficient.
  • Not all functions are suitable for inlining, such as recursive or very large functions.

Therefore, inline is usually applied to small, frequently called functions, like getters or simple utilities.

Example in Kotlin:

inline fun sum(a: Int, b: Int) = a + b

In conclusion, it is not advisable to declare all functions as inline — it is better to use it where there is a real performance gain.