Also, I'm counting Vector2 allocations (in a companion object field) and
turning on -XX:+DoEscapeAnalysis does not remove a single allocation.
The Vector2 class actually looks something like this:
case class Vector2(x: Float, y: Float) {
def +(a: Float) = Vector2(x + a, y + a)
def -(a: Float) = Vector2(x - a, y - a)
def *(a: Float) = Vector2(x * a, y * a)
def /(a: Float) = Vector2(x / a, y / a)
// rest of operations
}
I also tried making the class, it's methods and fields final but that
didn't change anything either. Scala's -optimize and -Yinline also had
no effect on performance (with relevant methods marked @inline final).
Erkki
Erkki Lindpere wrote:
> Yes. It helps (~15% overall improvement), but not as much as manual
> scalar replacement in source code has helped.
>
> Erkki
>
> Miles Sabin wrote:
>> On Sun, Jun 28, 2009 at 11:26 PM, Erkki Lindpere<
erkki@...> wrote:
>>
>>> * I think scalar replacement is what it's called -- given the type
>>> Vector2(x: Float, y: Float) { /* operations */ }, I want to replace
>>> 1) local variables:
>>> val v = new Vector2(1f, 2f) --> val v$x = 1f; val v$y = 2f
>>> 2) any operations on Vectors with operations on Floats
>>> 3) any escaping vectors with new Vector2(v$x, v$y) -- most of the
>>> time they
>>> will not escape
>>>
>>> Or should I just wait until JIT can do this better? :)
>>>
>>
>> Before trying to do this by hand, have you tried the
>> -XX:+DoEscapeAnalysis option of recent Sun JVMs?
>>
>> Cheers,
>>
>>
>> Miles
>>
>>
>