I'm using spEL 4.0.0.RELEASE to bind http parameters to java objects. I notice some strange problem while using expression parser multiple time: each invocation takes more time (constant). This happens only on java 8. On java 7 all ok.
Here is example code:
package ru.tersys.test;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
public class Test {
public static void main(String[] args) {
Test instance = new Test();
Table t = new Table();
Column c = new Column();
t.getColumns().add(c);
int counter = 10;
while (counter-- > 0)
{
instance.doTest("t", t);
}
}
ExpressionParser parser = new SpelExpressionParser();
StandardEvaluationContext context = new StandardEvaluationContext();
public void doTest(String prefix, Object obj)
{
Date d = Calendar.getInstance().getTime();
int counter = 0;
String el = "t.columns[0].name";
context.setVariable(prefix, obj);
String prefixWithDot = prefix + ".";
int count = 400;
while (count -- > 0)
{
if (el.startsWith(prefixWithDot))
{
parser.parseExpression("#"+el).setValue(context, "testColumnName");
counter++;
}
}
System.out.println("bind duration sec = " + (Calendar.getInstance().getTime().getTime() - d.getTime())/1000 + " param count = " + counter);
}
static class Table
{
public Table()
{
columns = new ArrayList<>();
}
public ArrayList<Column> getColumns() {
return columns;
}
public void setColumns(ArrayList<Column> columns) {
this.columns = columns;
}
private ArrayList<Column> columns;
}
static class Column
{
public Column()
{
}
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
jdk 8 output:
bind duration sec = 1 param count = 400
bind duration sec = 3 param count = 400
bind duration sec = 5 param count = 400
bind duration sec = 7 param count = 400
bind duration sec = 9 param count = 400
bind duration sec = 12 param count = 400
bind duration sec = 14 param count = 400
bind duration sec = 16 param count = 400
bind duration sec = 19 param count = 400
bind duration sec = 22 param count = 400
java 7 output:
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
bind duration sec = 0 param count = 400
Is this bug or feature? Is there any workaround?
It might be related to this JIRA Issue "Performance issues with SerializableTypeWrapper on Java 1.7.0_51", which was fixed in 4.0.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With