Answering your questions:
AD.1
As with everything in programming it depends. If it's a simple, short function, why not? If's a long complex function then I wouldn't do that. (Read the drawbacks) Also, JIT(Just-In-Time) performs inlining, you can read when it performs this optimization, and it should help you make the right decision.
AD.2
If you're dealing with limited memory environments or situations where code size is a concern, I'd avoid inlining. Compilation time takes too long? Also, avoid this kind of optimization.
AD.3
- Small methods
- Frequent calls (for example, a method called from a loop)
- Method is only called from one location (no risk of increased code size due to multiple call sites)
It's all about the trade-offs, that you can accept.
Generally, pros of inlining are:
Performance Optimization
- In Kotlin, a lambda expression creates a new anonymous class, which incurs memory and runtime overhead. By marking a higher-order function as inline, you're suggesting to the compiler that it should substitute the function's code directly at the call site, thus avoiding the creation of an additional class and function call overhead. Especially useful when these functions are invoked frequently within loops or in performance-critical code.
Control Over Function Inlining
- more control over when and where the function should be inlined, however, it doesn't guarantee that the function will always be inlined.
Inlining also has some drawbacks:
Code Size Increase
- Inlining functions can lead to an increase in code size, as the function's code is copied at every call site.
- Compile Time Increase
- Complexity Increases - Impact code readability and maintainability