0

I'm using Groovy 3.0.6 in my Java project as a scripting language, allowing the user to extend the application at runtime via groovy scripting. Some users have several hundred script snippets. I'm using GroovyClassLoader to load them (also CompileStatic, but that seems to have negligible impact).

My problem is that the parseClass method is extremely slow (more than 1 second compile time per script). Here's the profiler output of a JUnit test that compiles a bunch of scripts:

enter image description here The call tree. Note that I let the test run for 724 seconds and groovy is consuming 87% of the time for compilation. It strikes me as odd that LexerATNSimulator.getReachableConfigSet consumes so much time...

Profiler Output (Hot Spots) The hot spots of the test run. Unsurprisingly, nothing but groovy (and java.util) here.

The source code is given to the GroovyClassLoader.parseClass(...) method as a regular String. I do have a custom code cache in place, but the compilation of a single script hits my application hard when there are hundreds of snippets to compile.

Is there anything I can do to reduce compilation times? They're crippling for the user experience at the moment.

Martin Häusler
  • 6,544
  • 8
  • 39
  • 66
  • no way to improve performance of parse/compile step. however you could parse/compile groovy code only once. – daggett Nov 16 '20 at 17:30
  • similar question: https://stackoverflow.com/questions/45578426/lock-contention-in-groovy-shell-interpreter-under-high-load/45608419#45608419 – daggett Nov 16 '20 at 17:34
  • @daggett Unfortunately I have to re-compile when external things change (or when the script body itself changes). I do have a script cache in place to avoid re-compilation of the same script. – Martin Häusler Nov 16 '20 at 18:40
  • Then recompile on change and store both - original and compiled version. – daggett Nov 16 '20 at 18:56

0 Answers0