Lambda vs anonymous inner class performance: reducing the load on the ClassLoader?

后端 未结 2 1022
遇见更好的自我
遇见更好的自我 2020-12-10 15:49

I would like to know how big of a benefit lambdas have in Java 8. I agree that it might be more readable sometimes to use lambdas, but does it have really such of a big impa

相关标签:
2条回答
  • 2020-12-10 16:31

    Oracle has a presentation covering some of the performance differences. It appears that there are quite a few factors that impact performance of lambdas vs. anonymous classes.

    http://www.oracle.com/technetwork/java/jvmls2013kuksen-2014088.pdf

    0 讨论(0)
  • 2020-12-10 16:39

    After reading the PDF linked from @Brett Okken I believe the following holds:

    • Inner classes have a slightly slower performance on first use, but it seems negliable.
    • Lambdas have a slower performance when called often because of the bigger stack they build up when called.

    I will stick with the following:

    • Use Lambdas for readability when a few milliseconds performance loss is not a problem (GUI stuff, etc.)
    • Use inner classes for often called, performance critical functions.
    0 讨论(0)
提交回复
热议问题