Lambda vs匿名内部类性能:减少ClassLoader的负载? [英] Lambda vs anonymous inner class performance: reducing the load on the ClassLoader?

查看:249
本文介绍了Lambda vs匿名内部类性能:减少ClassLoader的负载?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道lambdas在Java 8中有多大的好处。我同意有时使用lambdas可能更具可读性,但是它对性能方面有多大影响吗?或者主要是作为语法糖? 我有时更喜欢匿名的内部课程;当我不经常使用lambda时,我真的会失去很多好处吗?

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 impact on the performance side? Or is it mainly focused as syntactic sugar? I prefer anonymous inner classes sometimes; do I really lose many benefits when I don't use lambda all the time?

唯一的?大?在我看来,性能增益是我们实际上并没有创建类加载器必须在程序开始时加载的类 - 例如创建许多线程:

The only ?big? performance gain, it seems to me, is that we don't actually create classes that the class loader has to load at the start of the program -- for example creating many many threads:

Thread t = new Thread(new Runnable() {
   public.....
});

创建类似示例$ 1.class

除此之外,代码的可读性或可维护性等是否有任何性能或其他隐藏的收益?隐藏在JVM的某处?我见过类似的问题,但大多数都集中在视觉方面;我对此不感兴趣。在使用Venkat Subramaniam观看 Java 8 Lambdas Hacking 后,问题出于好奇。

Other than that, is there any performance or other hidden gain besides readability or maintainability etc. of the code? Hidden somewhere in JVM? I've seen questions similiar to this but most of them were focused on visual side; I'm not interested in that. The question is out of curiosity after watching Java 8 Lambdas Hacking with Venkat Subramaniam.

推荐答案

Oracle有一个演示文稿,介绍了一些性能差异。似乎有很多因素会影响lambdas与匿名类的表现。

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

这篇关于Lambda vs匿名内部类性能:减少ClassLoader的负载?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆