I have a long method that consists of about 350 lines. It's a routine method that another method uses in a cycle and it uses it many times (I'm talking here about numbers greater than 100 000).
The routine method has many conditional branches dependent on some computations. The computations in each branch look like this:
...
double cosValue = Math.cos(finalAngle);
double sinValue = Math.sin(finalAngle);
double baFirst_rotated_x = b.getA().getFirst().getxCentroid() * cosValue - b.getA().getFirst().getyCentroid() * sinValue;
...
So the heap space needed is not of a small size. The application works fine, but it's really slow.
Weird thing is that when I add a System call, for example, it runs much faster (like 10x faster). So when I put this
System.out.println("..."); or System.gc();
inside the routine method, it performs better. It looks like the System call somehow unpauses the application. Could someone please give me a hint why this might be happening? I know this is a very indefinite question and I apologise for that. I just think that there must be an explanation of what's actually happening and I can't move on without knowing it.