Strange performance issue

Hi,

I've been programming Java professionally for 10 years and I've seen som weird sh*t over the years, but this one takes the cake:

I have a huge complex application that does all kinds of funny stuff with doubles. In a specific test case, one method is called ~3000 times and covers 25% of total execution time, so I figured I'd optimize it a bit.

To cut a long story short, by accident, I discovered that ADDING one single line to this one method consistently reduced total test time from 3.9sek to 2.6sek:

m_Limits =new double[1];

m_Limits is a private membership variable that is NEVER accessed anywhere else - this is the only time this member is ever touched.

changing it to

if(m_Limits==null) m_Limits =new double[1];

Took off an additional 0.2sek, but moving it to the constructor removed the optimization entirely. The same happens if m_Limits is declared as a local variable.

Have I run in to some kind of hotspot fluke - has anyone else ever experienced anything like this?

[1051 byte] By [JudgeJa] at [2007-10-3 3:57:07]
# 1
hi there... v interesting...would it be possible to show that complete method that can be excuted as standalone?
fuishiena at 2007-7-14 21:55:27 > top of Java-index,Java HotSpot Virtual Machine,HotSpot Internals...
# 2

The code is not all that big, but it would take me quite a while to isolate it - time that I haven't really got. Anyway, I doubt you'd see the same behaviour out of context.

The thing is that this is part of a larger optimization and it needs to be there for other reasons, so I don't really need to know why it's faster. I'm happy for whatever speed increases I can get.

Not sure why I even posted this as I haven't got neither time nor motivation to pursue it. Spur of the moment I guess.

Thanks for reading though ;)

JudgeJa at 2007-7-14 21:55:27 > top of Java-index,Java HotSpot Virtual Machine,HotSpot Internals...