Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.8.6
-
Fix Version/s: 2.0-beta-3, 1.8.7
-
Component/s: None
-
Labels:None
-
Environment:Grails 2.0.3 + Groovy 1.8.6
-
Number of attachments :
Description
This problem is a major performance bottleneck in Grails 2.0 applications.
Currently this problem shows up when resources plugin has been installed and used in a Grails app. (see attached screenshot)
Exceptions are relatively heavy weight in Java. Filling the stacktrace takes most of the time. Normal execution flow should never throw exceptions.
(it is possible to disable filling the stacktrace like has been done for MissingMethodExceptionNoStack, in that case the performance overhead is usually acceptable.)
The problem shows up whenever there is 2 classes sharing the same base class and when the other class is a Java class and the other one is a Groovy class (GroovyObject).
I was able to reproduce the problem with this code. Run this code in a debugger and make a breakpoint for the construction of ClassCastException.
In this example the base class is java.util.Map , the Java class is LinkedHashMap and the Groovy class is MyMap (extends LinkedHashMap).
class ClassCastProblem {
def doCalls() {
def m1=[abc:'test']
def m2=new MyMap()
doSomething(m1)
doSomething(m2)
doSomething(m1)
doSomething(m2)
doSomething(m1)
}
void doSomething(m) {
m.remove('test')
}
public static void main(String[] args) {
def ccp=new ClassCastProblem()
ccp.doCalls()
}
}
class MyMap extends LinkedHashMap {
}
In a Grails app the 2 different java.util.Map implementations usually triggering this problem are LinkedHashMap and GrailsParameterMap (GroovyObject).
In Grails core I've worked around some of the problem with this type of hack:
https://github.com/grails/grails-core/commit/62626921ebd80e3cdeb9776fd79be7eb92f88763
At that time I didn't have time to investigate the reason that caused the problem and just made some changes until the problem went away.
Activity
| Field | Original Value | New Value |
|---|---|---|
| Attachment | 0001-Fix-for-GROOVY-5428-Eliminate-ClassCastExceptions.patch [ 59790 ] |
| Status | Open [ 1 ] | Closed [ 6 ] |
| Assignee | blackdrag blackdrag [ blackdrag ] | |
| Fix Version/s | 2.0-beta-3 [ 18244 ] | |
| Fix Version/s | 1.8.7 [ 18317 ] | |
| Resolution | Fixed [ 1 ] |
Example with Lists & find:
class ClassCastProblem2 { def doCalls() { def l1=['a','b','c'] def l2=new MyList() doSomething(l1) doSomething(l2) doSomething(l1) doSomething(l2) doSomething(l1) } void doSomething(l) { l.find { it } } public static void main(String[] args) { def ccp=new ClassCastProblem2() ccp.doCalls() println('done') } } class MyList extends ArrayList { }The problem shows up also with DGM methods.