In Portofino, we use GroovyScriptEngine which takes care of automatically
recompiling changed files (taking dependencies into account). A typical
application has dozens of such files and it works well for us. However,
those are full-blown classes (even if many of them trivially extend a given
base class) rather than expressions. But you could still collect all the
expressions related to a given resource or page into a single class quite
easily if performance becomes a problem.

On Tue, 27 Oct 2020 at 16:08, Edmond Kemokai <ekemo...@gmail.com> wrote:

> 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