Word - Spring JIRA

advertisement
[SPR-13638] Allow SpelCompiler to compile MapAccessor expressions Created:
04/Nov/15 Updated: 17/Dec/15 Resolved: 23/Nov/15
Status:
Project:
Component/s:
Affects
Version/s:
Fix Version/s:
Closed
Spring Framework
Core:SpEL
4.2.2
Type:
Reporter:
Resolution:
Labels:
Remaining
Estimate:
Time Spent:
Original
Estimate:
Improvement
Priority:
Daniel Fernández
Assignee:
Complete
Votes:
spel, spelcompiler, thymeleaf
Not Specified
4.2.4
Major
Andy Clement
0
Not Specified
Not Specified
11 weeks ago
Days since last
comment:
Last commented false
by a User:
Stéphane Nicoll
Last updater:
Description
Thymeleaf 3.0 will modify the way in which SpEL expressions are executed inside templates.
One of the modifications will be that the context object (containing all the variables usable in
expressions) will be passed to the SpEL evaluation engine wrapped as a Map, so that for most
expressions (though not all), the use of custom PropertyAccessor will not be needed. And that's
good because that's one of the conditions for the SpEL compiler to be able to run.
The problem is, a good amount of expressions in Thymeleaf templates look like:
${someobject.someproperty}
The "someproperty" part (which will internally use introspection on the "someobject" object)
should be covered by the SpEL compiler... but the first part of the expression, "someobject", is
obtained from a (wrapped) map. So in this case, given the expression includes the use of a nonintrospection-based accessor, compilation is not performed at all.
It would be great therefore if the use of MapAccessor was included in the SpEL compiler
capabilities, so that expressions as the one above could be compiled in Thymeleaf 3.0 templates
(if the compiler is configured).
Of course, this would make expressions such as:
${someobject}
...which might be even more common, to be compilable too. But in such case no introspection is
involved, so I doubt we would obtain any real performance gain. That's why I focus on twolevel expressions.
Comments
Comment by Andy Clement [ 23/Nov/15 ]
Implemented code generation for MapAccessor, it will now be compiled. Some basic numbers
for a million iterations of various expressions.

expression is a simple key name "foo" and the root object is a map:
Interpreted: 92ms Compiled: 15ms

expression is a key name and then a method invocation "foo.toUpperCase()" and the root
object is a map:
Interpreted: 568ms Compiled: 56ms

expression is a sequence of key names "foo.bar" and the root object is a map of maps:
Interpreted: 297ms Compiled: 20ms

expression is a sequence of key names and then a method invocation
"foo.bar.toUpperCase()" and the root object is a map of maps:
Interpreted: 700ms Compiled: 60ms
Comment by Daniel Fernández [ 23/Nov/15 ]
That's awesome, thanks! I wasn't expecting such an improvement in Map-only expressions, but
those figures look really good...
Comment by Juergen Hoeller [ 23/Nov/15 ]
Nice - to be rolled right into 4.2.4 then... Thanks, Andy!
Juergen
Generated at Tue Feb 09 10:37:01 UTC 2016 using JIRA 6.4.11#64026sha1:78f6ec473a3f058bd5d6c30e9319c7ab376bdb9c.
Download