groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Winnebeck, Jason" <>
Subject JDK8 Streams / Closure cast to interface
Date Tue, 22 Nov 2016 14:14:31 GMT
I love Groovy. I also love the new streams functionality in JDK 8. But, I am weary of the performance
implications of Groovy + Streams, because to use streams you must use Groovy closures. I see
the code generated creates a new closure instance then uses castToType to cast the closure
to the JDK8 functionality interface. Does Groovy make this efficient, or is the proxy generation
from this going to be excessive if running a lot of small stream operations?

I think an interesting feature of Groovy would be if it sees a closure cast implicitly or
explicitly to a certain interface type, it could make the closure implement the interface.
You'd still have the overhead of compile-time class generation versus lambdas, but at least
you wouldn't have to create proxies, and maybe there is an improved chance of JIT inlining?
Even if it was supported within a single statement, like "Function<String, String> x
= {it.trim()}" or Stream.of("abc").map { it.trim() }, the closure with trim could implement
Function. Of course for backwards compatibility the class could still extend Closure and still
implement call methods, but also implement the method apply, which delegates to call.

Jason Winnebeck
Software Engineer III Contractor - IT Software Development | Windstream
600 Willowbrook Office Park, Rochester, NY 14450<> |
o: 585.794-4585

This email message and any attachments are for the sole use of the intended recipient(s).
Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the
intended recipient, please contact the sender by reply email and destroy all copies of the
original message and any attachments.

View raw message