groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jochen Theodorou <blackd...@gmx.org>
Subject Re: Integer primitive division
Date Sat, 24 Oct 2015 09:07:11 GMT
On 23.10.2015 22:47, Winnebeck, Jason wrote:
> Is there any way to perform primitive integer division in Groovy compile
> static mode? If I do:
>
> (int)(12/2)
>
> Then it coverts 12 and 2 to Integer objects, calls a method that
> performs BigDecimal division, then calls “as int” (not just intValue) on
> the result, which itself does instanceof checks.
>
> I tried intdiv, and it is more efficient, but it still converts to and
> from Integer objects so that it can do A.intValue() / B.intValue(), and
> storing that result in an Integer itself.

I think I did do an optimization for this kind of thing for double, but 
I may not have done that for int... normally if you do something like

int i = 12/2

the compiler should be able to optimize this to a normal int division 
like in Java for primopts and compilestatic.. checking now I find a

     BIPUSH 12
     ICONST_2
     IDIV
     ISTORE 3

meaning it works for primopts, but not for compilstatic. Probably, 
because in normal Groovy we do not prevent conversions with loss for 
numbers, while copilestatic insists of the div resulting in a 
BigDecimal. And then primopts fail to help compilestatic.

Not sure if I should really qualify that as static compilation bug

As for intDiv... ideally the JVM does optimize the overhead away. But 
considering optimizations being done here for primopts as well as the 
invokedynamic version I think some work should be invested here.

An improvement report for this would be a good start

As for "What I’m wondering is if Java is strictly required if 
performance is a concern with division." Did you check the impact of this?


bye blackdrag

Mime
View raw message