You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@groovy.apache.org by Alain Stalder <as...@span.ch> on 2015/08/23 09:50:45 UTC

Share MetaClass state between classes based on same bytecode?

I load the same set of compiled Groovy scripts with several separate
class loaders. Say, I have a script "MyScript.groovy" that results
in a class called MyScript. Now, for each class loader, a separate
MyScript class instance will be created and by default, a new
instance of an associated MetaClass with be created, initialized
and stored in the MetaClassRegistry, even though these classes have
the same methods and so on. This costs quite a bit of time and memory.

What I would like to do instead, is determine meta information just
once per same bytecode and reuse it in several lightweight MetaClass
instances.

What kind of options do I have? What do I have to consider?

Make a copy of MetaClassImpl, modify it, and set an instance of it
in the registry when loading a class?

Or is there a better way that involves copying less code (which is
not so robust against Groovy upgrades)?

Alain