Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpEL: reduce restrictions on compiling mathematical expressions [SPR-12789] #17386

Closed
spring-issuemaster opened this issue Mar 5, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Mar 5, 2015

Andy Clement opened SPR-12789 and commented

A few people have noticed that we are currently quite strict on what mathematical expressions we will 'compile' in SpEL. For the standard operators (plus, minus, divide, multiply) we require the operands to be exactly the same type. E.g. both ints, both doubles, both floats, etc. Due to this strict rule you sometimes have to write something funky to get the compiler to compile your expression:

(T(java.lang.Double).parseDouble(payload.someBoxedInt.toString()))/60D

Basically perform a conversion yourself to ensure the operands are compatible. This was done deliberately as we didn't have use cases and every bit of extra flexibility needs many more test cases and enhanced byte code generation - some of the expressions you can write naturally in Java cause extra byte code to be generated that you aren't aware of for converting numbers and we'd need to start generating that too (instructions like i2d). The XD/Integration teams have hit this problem a couple of times.

Under this jira I'd try to lift the restriction.

Juergen (or someone) - are there any upcoming deadlines that you would want me to hit (or not hit) with this feature?


Affects: 4.1.5

Referenced from: commits b7ef047

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2015

Juergen Hoeller commented

Hey Andy, 4.2 would be a perfect target here, with 4.1 RC1 due on May 20th...

Juergen

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2015

Andy Clement commented

Delivered this morning. With a mountain of tests. I decided to fix add/subtract/divide/multiply and modulus.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 6, 2015

Andy Clement commented

Oh, some numbers:

Performance check for SpEL expression: '(T(Integer).valueOf(payload).doubleValue())/18D'
Interpreted run:
One million iterations: 63115ms
One million iterations: 61648ms
One million iterations: 60963ms
Now compiled:
One million iterations: 18ms
One million iterations: 14ms
One million iterations: 14ms
Performance check for SpEL expression: 'payload/18D'
Interpreted run:
One million iterations: 164ms
One million iterations: 145ms
One million iterations: 150ms
Now compiled:
One million iterations: 15ms
One million iterations: 12ms
One million iterations: 14ms

Basically before these changes the expressions were more complex and slow in interpreted mode (but your intention was to activate the compiler). With these changes the expression is simpler and faster both interpreted and compiled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.