The current way of generating proxies, for example when you convert a map to an object using the "as" keyword is highly inefficient. Generating a proxy for a concrete class, in that situation, is two orders of magnitude slower than generating a proxy for an interface with the JDK proxy mechanism.
This can be improved in two way:
- use ASM based class generation instead of creating a string which is converted to a class thanks to a GroovyShell
- implement proxy class caching so that subsequent conversions of similar objects reuse the same generated class instead of always generating a new class
The pull request (see comment) is such an implementation, which performs way better than the legacy version. For example, using the following script:
Groovy master shows:
I'm using a pull request and adding a breaking label to this issue because even if all the unit tests pass, I suspect the test coverage is insufficient so I'd be keen for code review.