Reputation: 32221
I am writing a game for android, and I am worry about performance and memory. Is Java less effective with many classes?
Upvotes: 3
Views: 409
Reputation: 20059
The number of classes is practically irrelevant when it comes to performance. Generally there are many other areas that usually have much greater impact on perceived performance (we are talking about magnitudes here, not a few percent).
It also depends of what you consider many classes. I would consider >30K classes many (I worked in a project that had this many classes), but you probably already consider 1K classes many (and 1K is nothing, really). Usually the only notable effect of adding another 10K classes (that are also used, mind that classes not loaded do not measurably affect performance) is to add a few more seconds of startup time.
Focus on correct function first, worry about performance when you achieved that. The only performance consideration you should have while working on function is the choice of suitable data structures and algorytms. Chosing proper data structures and efficent algorytms has far greater impact than shaving off a fraction of a percent in the area of class loading.
Upvotes: 0
Reputation: 4137
Back in J2ME days, where some devices had a limit of 64k jar (for example) -
usage of lots of classes affected the jar size, and one of the tricks was to reduce number of classes.
The only overhead you will have is class loading of each one of these classes.
Not sure if this happens on startup or during first access/allocation to object of a given class (or combination of both in some manner),
but this is truly not an issue.
Upvotes: 0
Reputation: 1943
Its not so much the classes that you have to worry about. Much rather it depends on the number of Objects that you instantiate and the frequency with witch they are dereferenced and hence have to be cleaned up by the GC.
So if anything keep an eye on the number of Objects beeing created and dereferenced.
Upvotes: 0
Reputation: 66637
Many classes affect performance?
I don't think so. Only one thing would be at startup it will be little slow (negligible) to load all classes to memory (Which is optimized with newer versions).
Upvotes: 5