When writing something that creates many (1000s) of small objects often, should you try to minimize it for performance? Especially if you don't know what system it will be run on, from low to high end desktops or even mobile. For mobile, I heard that creating a lot of objects hinders the performance a good bit, though I don't know how true that is.
I have an example that shows this idea well. In a graphics program, say there is a method that is used for all drawing ideally called drawPixel(Point)
. There could be 1000s of Points created and it may be repeated often, like in a game where it could be called 60+ times a second. Alternatively, drawPixel(int x, int y)
could be used to minimize the creation of many Point objects.
In an object-oriented design, I think using Point would be preferred. However, using primitive types may increase performance. The performance gain may be negligible in most cases, but I'm unsure about things like mobile or older machines. What is the performance gain from doing something like this and is it something that should be taken into consideration?
System.getProperty("java.version")
(or "java.vm.version") is a starting point.