Kind of a generic question, but I'm just wondering if I'm better off with one large static hash map or breaking it into a few smaller ones. It would be for a web app. Thanks.
As a rule, I'd suggest Do The Simplest Thing That Can Possibly Work until somebody proves it won't work - ie a real profiling tool shows the code takes too much time. As a good design and hedge if you're worried, hide the implementation behind a simple interface or wrapper class so that if you have to change it from one map to multiple maps later no other classes are broken.
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Kind of a generic question, but I'm just wondering if I'm better off with one large static hash map or breaking it into a few smaller ones. Are you storing homogenous data in your map? Forget Java and programming, -- would you put these things into one or several different containers?
It could be one container, but if I wanted to, I could break it down into multiple containers. Just like you could have "cars", and you could break that down into different models of cars. For now, the top level container would be fine, but if I use one map, I'll only be using a portion of it at a time (depending on which JSP page is called.
Then it depends mainly on the distribution of the objects hash codes. If they are well distributed, it shouldn't make a difference.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Ilja: Then it depends mainly on the distribution of the objects hash codes. If they are well distributed, it shouldn't make a difference. Sounds to me like Mark is having a design problem, not a performance problem (although the fact that he posted here may suggest otherwise). I wouldn't think in terms of the distribution of the hash codes if the question is "what is a better design?". Perhaps Mark can clarify.
Originally posted by Mark Stein: Eugene, you got it right. I'm in the design phase of a project right now, and was looking to factor in efficiency as I lay stuff out.
That's a very slippery slope. It's much better to lay out stuff for maintenance and tackle performance problems as they arise.
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
I'm with Ilja on this one. The first rule of coding for performance is "don't". The second rule is "follow the first rule unless you are an expert AND are having performance problems."
IP: That's a very slippery slope. It's much better to lay out stuff for maintenance and tackle performance problems as they arise. I am in full agreement with that.
To make the advice a little bit more practical: Design your system so that only a minimal part of it knows about the number of HashMaps you use - that is, encapsulate that knowledge into a single place. That way it will be easy to switch between those two implementation details once you have real data on performance issues. Hope this helps...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus