[
https://issues.apache.org/jira/browse/GROOVY-9601?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17145008#comment-17145008
]
Daniel Sun commented on GROOVY-9601:
------------------------------------
According to [~blackdrag]'s suggestion, I ran Jochen's script with 2.5.12 and
the 4.0.0-SNAPSHOT( [https://github.com/apache/groovy/actions/runs/147560316] ).
[^Groovy9601.groovy]
Here is the result(antlr4 parser runs almost as fast as antlr2 parser now):
{code:java}
D:\_TEMP\wwww>groovy -v
Groovy Version: 4.0.0-SNAPSHOT JVM: 11.0.6 Vendor: Amazon.com Inc. OS: Windows
10
D:\_TEMP\wwww>groovy Groovy9601.groovy
time = 362.188ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
time = 340.7452ms
D:\_TEMP\wwww>set JAVA_OPTS=-Dgroovy.antlr4.cache.threshold=50000
D:\_TEMP\wwww>groovy Groovy9601.groovy
time = 378.2312ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
time = 343.5271ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
time = 348.2159ms
D:\_TEMP\wwww>
{code}
{code:java}
D:\_TEMP\wwww>groovy -v
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.codehaus.groovy.reflection.CachedClass
(file:/D:/_DEV/Groovy/groovy-2.5.12/lib/groovy-2.5.12.jar) to method
java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of
org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
Groovy Version: 2.5.12 JVM: 11.0.6 Vendor: Amazon.com Inc. OS: Windows 10
D:\_TEMP\wwww>groovy Groovy9601.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.codehaus.groovy.reflection.CachedClass
(file:/D:/_DEV/Groovy/groovy-2.5.12/lib/groovy-2.5.12.jar) to method
java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of
org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
time = 364.9886ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.codehaus.groovy.reflection.CachedClass
(file:/D:/_DEV/Groovy/groovy-2.5.12/lib/groovy-2.5.12.jar) to method
java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of
org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
time = 347.306ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.codehaus.groovy.reflection.CachedClass
(file:/D:/_DEV/Groovy/groovy-2.5.12/lib/groovy-2.5.12.jar) to method
java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of
org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
time = 359.1594ms
D:\_TEMP\wwww>groovy Groovy9601.groovy
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by
org.codehaus.groovy.reflection.CachedClass
(file:/D:/_DEV/Groovy/groovy-2.5.12/lib/groovy-2.5.12.jar) to method
java.lang.Object.finalize()
WARNING: Please consider reporting this to the maintainers of
org.codehaus.groovy.reflection.CachedClass
WARNING: Use --illegal-access=warn to enable warnings of further illegal
reflective access operations
WARNING: All illegal access operations will be denied in a future release
time = 348.4105ms
D:\_TEMP\wwww>
{code}
> 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
> Assignee: Daniel Sun
> Priority: Major
> Fix For: 4.0.0-alpha-1, 3.0.5
>
> Attachments: 50000.png, Groovy9601.groovy,
> image-2020-06-25-17-42-31-315.png, no_tuning.png
>
>
> 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)