Does anybody knows, why method below is inlined always?
public inline fun <T : AutoCloseable?, R> T.use(block: (T) -> R): R
We can create lambda for this case in heap (e.g. instead of method inlining - just do library call).
- Inline methods increase total byte code soze, e.g. increases application complexity from JVM side
- The same code is copy-pasted multiple time, so JIT could not understand, that optimization of it can be the same
closemethod is called for case, when we are going to create new objects in heap. This means, that we can create one more object (e.g our function and closed variables) without any big affect (instead of collection iteration, etc.).
- Inline functions are not default for JVM, e.g. it is better to use them as less as possible
- If JVM really need to inline this method, it can do this by itself.
Do we have performance reasons for this function inlining? Do we have any other reasons to do this?