Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
2.1.7
-
None
Description
GString implementation of String's method is very expensive. With trim(), it can be 10 times slower than String's counterpart.
Steps to reproduce:
A small test program showed GString.trim() is 10 times slower than String.trim().
def a = " content " def b = " ${'content'} " println "a class: ${a.class}" //output: class java.lang.String println "b class: ${b.class}" //output: class org.codehaus.groovy.runtime.GStringImpl long start = System.currentTimeMillis() 10000000.times { a.trim() } println "String trim completed in ${System.currentTimeMillis() - start} ms." //output *909* ms start = System.currentTimeMillis() 10000000.times { b.trim() } println "GString trim completed in ${System.currentTimeMillis() - start} ms." //output: *9321 *ms
We can get around the problem by calling toString() on GString before invoking methods, BUT it should be supported inside the Groovy runtime.
More info at this thread: http://markmail.org/thread/4cti6dgb7pmrzqbl
Attachments
Issue Links
- is related to
-
LOG4J2-3017 Groovy logging of GString with $ notation is very slow
- Closed
- links to