groovy-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alain Stalder <>
Subject Improve Groovy class loading performance and memory management
Date Fri, 13 May 2016 00:22:02 GMT
Hi everybody

I had considered to submit a major feature request for Groovy with the 
text further below, because it appears to me that there might possibly 
be considerable room for improvement, but since I am not developing 
Groovy myself I thought that maybe I would just present it here and if 
people think such a feature request (or a somewhat similar one) would 
still make sense, it could still be created (by me or someone else)...

Improve Groovy class loading performance and memory management

Consider the maybe most typical use case of Groovy as a dynamic 
language: Within a Java VM, Groovy scripts are dynamically compiled, be 
it explicitly by using a GroovyShell or a GroovyClassLoader, or more 
implictly e.g. with a ConfigSlurper.

Qualitatively this often has the following result in the Java VM: 
Metaspace resp. PermGen, and Heap in parallel, just grow until a 
configured limit is reached (and note that there is none by default for 
Metaspace in Java 8 and later), often only then is it garbage collected. 
With Java classes, at least with simple ones, this looks often 
different, those appear to be garbage collected much more quickly.

Another qualitative difference is that loading a Groovy class and 
instantiating it seems typically to be considerably slower than 
instantiating a Java class with similar functionality, even quite 
drastically so, more than one would expect even considering the need to 
create metadata for dynamic function calls etc.

At least that has been my experience over the past few years.

Seen from very far ("management", "marketing", "sales"), this not 
optimal for a dynamic language, getting these two things right - memory 
management and class loading performace -  is arguably "core business".

Obviously Groovy classes are more complex than most Java classes and 
there is existing code and limitations of Java VMs and probably more 

But in the medium term, I think and feel that it would be good to find 
out what really impedes better performance and a more regular garbage 
collection. Possibly the problems are really hard and complex, but some 
might also be easy, and maybe some would become quite easy after some 
simple changes in the Java VM, but before such changes can be requested, 
it has to be analyzed what these could or should be.

Attached is a simple command line Java test program,, 
that can be used to make some very basic measurements of class loading 
memory behavior and performance. The source code and a readme with two 
examples (one for Java and one for Groovy) is also at, and I think it might help to 
illustrate current limitations and maybe also a little bit initially 
with analysis.

Note the tool at and the readme with 
two illustrative examples - one Java class, one Groovy class - there...


View raw message