[CLJ-740] Unnecessary boxing of primitives in case form Created: 17/Feb/11 Updated: 15/Sep/14 Resolved: 15/Sep/14
|Affects Version/s:||Release 1.3|
Found this while profiling some performance-critical code.
Consider the following Clojure function:
Current Clojure 1.3 snapshot compiles it to:
This bytecode contains boxing of primitives (calls to clojure/lang/Numbers.num and java/lang/Double.valueOf) and calls to clojure/lang/Util.hash and clojure/lang/Util.equals that does not seem necessary.
At 60-66 primitive double is boxed into Double only to be converted back into primitive.
The equivalent Java code compiles to much simpler and faster bytecode:
|Comment by Alexander Taggart [ 28/Feb/11 2:16 PM ]|
Improved via patch on
now emits as
or if the int cast of the expression is omitted:
|Comment by Ghadi Shayban [ 14/Sep/14 10:00 PM ]|
I can't reproduce this on -master. No boxing here:
|Comment by Alex Miller [ 15/Sep/14 10:54 AM ]|
The case stuff has been worked on several times (including in 1.6) since it's release, so it's likely this was fixed as a side effect of prior changes.