Is there a big difference in efficiency when using Point2D instead of double x and y values?
I'm working on a program that has many circles moving around the screen. They each start at one point, and get closer and closer to their destinations (finally, they stop).
Using methods like .getCurrentLocation().GetY() (where currentLocation is a Point2D), I'm experiencing slow performance with any large number of entities.
I don't want to go back and revise all my code for no reason, so I'm asking if I would see a significant performance increase from just storing X and Y double coordinates instead of using Points.
First of all, you should use a profiler to find out what's causing the poor performance. I use YourKit, but there are others.
If Point2D is indeed the problem, you could represent your points as two double arrays, one for all x coordinates and one for all y coordinates. This is likely to be a lot faster than keeping a collection of Point2D objects.
That depends on whether you constantly create new points. If not, i.e. you reuse the existing ones, you shouldn't get a big performance difference.
What is costly about objects in most cases is not the storage but the object creation.
However, as suggested by aix, try and use a profiler to find the real performance bottlenecks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With