Function Inlining
Lambdas are useful because they enable a high degree of flexibility in how your programs can be written. However, that flexibility comes at a cost.
When you define a lambda, it is represented as an object instance on the JVM. The JVM also performs memory allocations for all variables accessible to the lambda, and this behavior comes with associated memory costs. As a result, lambdas introduce memory overhead that can in turn cause a performance impact – and such performance impacts are to be avoided.
Fortunately, there is an optimization you can enable that removes the overhead when using lambdas as arguments to other functions, called inlining. Inlining removes the need for the JVM to use an object instance and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access