Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
316 views
in Technique[技术] by (71.8m points)

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

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.....
});

creates classes like Sample$1.class.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...