Hi Jason,

I am working on a product that uses Groovy as a dynamic scripting language
within a Java web app and have been contending with this concern as well.

Some things to consider:

Is it possible to consolidate these 100s of expressions into a fully
qualified named class?
With this approach you could then create a singleton of such a class and
retain that in memory via the java web app session. You could then map the
expression evaluation to some sort of naming scheme (basically a bunch of
if/else blocks), or just map each expression to a unique function.

This of course takes away some of the flexibility of being able to run
arbitrary code.

As to the overhead of constantly compiling these expressions, I can't speak
to actual numbers but there is definitely an overhead, you'll probably need
to do your own jvm performance profiling to determine whether it is an
actual problem.

In my case I am using the java scripting API to evaluate Groovy code, with
that API it is possible to obtain a compiled instance of the code (
javax.script.CompiledScript ) that can be rerun multiple times without
recompiling. This is an alternative way to address compilation overhead.

Hope this helps.

Regards
Edmond

Reply via email to