You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2020/06/22 16:04:00 UTC

[jira] [Commented] (GROOVY-9601) Parsing text into a class became much slower under Groovy 3.x

    [ https://issues.apache.org/jira/browse/GROOVY-9601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17142229#comment-17142229 ] 

Eric Milles commented on GROOVY-9601:
-------------------------------------

You can switch back to the Antlr2 parser for now.  In Groovy 4, this will not be an option.  To do this, you can set system property "groovy.antlr4" to false or you can pass a CompilerConfiguration – that sets pluginFactory to ParserPluginFactory.antlr2() -- to your GroovyClassLoader.

There are also some caches that can be disabled with some system properties.  You'll probably need to do some digging to figure out if your slowness is from parsing only or from other enhancementes in Groovy 3.

> Parsing text into a class became much slower under Groovy 3.x
> -------------------------------------------------------------
>
>                 Key: GROOVY-9601
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9601
>             Project: Groovy
>          Issue Type: Bug
>          Components: class generator
>    Affects Versions: 3.0.4
>         Environment: Openjdk 11
>            Reporter: Fabian Depry
>            Priority: Major
>
> Our Java application needs to execute dynamically generated Groovy code and we use the GroovyClassLoader to create a class from that generated code.
> When we tried to upgrade to Groovy 3.x we noticed a huge bump in the time it takes to create those dynamic classes (it became 10 times slower for some of them).
> Here is a very simple example of how we use the class loader:
> {code:java}
> package lab;
> import groovy.lang.GroovyClassLoader;
> public class GroovySpeedLab {
>     public static void main(String[] args) {
>         StringBuilder buf = new StringBuilder();
>         buf.append("package lab\r\n");
>         buf.append("\r\n");
>         buf.append("import groovy.transform.CompileStatic\r\n");
>         buf.append("\r\n");
>         buf.append("@CompileStatic\r\n");
>         buf.append("class MyClass {\r\n");
>         for (int i = 0; i < 1000; i++) {
>             buf.append("\r\n");
>             buf.append("    public void myMethod").append(i).append("() {\r\n");
>             buf.append("        println('method ").append(i).append(" invoked...')\r\n");
>             buf.append("    }\r\n");
>         }
>         buf.append("}\r\n");
>         long start = System.currentTimeMillis();
>         new GroovyClassLoader().parseClass(buf.toString());
>         System.out.println("Done parsing in " + (System.currentTimeMillis() - start) + "ms");
>     }
> }
> {code}
> While this runs very quickly (because the methods are trivial), it it still consistently 50% slower with 3.x (but I am including this example mainly to show our use-case, not to focus on its speed difference).
> Our real application has much more complex classes (and many of them) and its initialization went from a couple of minutes to 10+ minutes.
> Is there another way to parse a given Groovy class without taking such a big performance hit with the new version of Groovy?
> Note that we also use many small Script objects created by calling GroovyShell.parse() and we noticed the same performance hit for those (I assume it uses the same mechanism under the hood).
>  
>  
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)