Comments inline...


Stephen Colebourne wrote:
From: "__matthewHawthorne" <[EMAIL PROTECTED]>

When you say that Flat3Map is faster than HashMap for <= 3 gets/puts,

er <= size 3. You can get/put as often as you like, without exceeding size 3.

Sorry, I just phrased that wrong. I knew that you meant size<=3




 My concern is always the cost required to obtain this situation.  I'll
always prefer a nice clean object oriented solution over one that is
tweaked for performance.  I'll never avoid using a complex type or
creating an object just because it will hurt performance.  Whether this
preference is practical in the real world, I'm not sure.

Well of course the point here is that as far as the API user is concerned there is no change - you just use a Map interface. Do you need to care how it is implemented?

You're right - once again I phrased this wrong. From the user's perspective there is no difference. My point was to question whether "performance tweaked" code is the type of thing that we want to add to commons. I'm not convinced that classes specific to certain number of Map or List entries would be useful additions. Obviously, I can only speak for myself - does anyone else have a need for such a thing?




Question: Did you try testing HashMap with different values for
initialCapacity and loadFactor?

Actually I just did some more tests: Create new Flat3Map() vs create new HashMap() 2910 vs 4060

Create new Flat3Map() put 3 mappings vs create new HashMap() put 3 mappings
4170 vs 8120

Memory usage
Size 0: 56 bytes vs 120 bytes
Size 1: 56 bytes vs 144 bytes
Size 2: 56 bytes vs 168 bytes
Size 3: 56 bytes vs 192 bytes
Size 4: 272 bytes vs 216 bytes
Size 5: 296 bytes vs 240 bytes

Object creation on construction:
None vs Entry[16]

Maybe I wasn't specific enough. Did you try creating a HashMap using an initial capacity of 3 [ via new HashMap(3) ]? In this case, I believe that only 3 objects are created on construction. I think that setting the loadFactor to 1 [ via new HashMap(3,1)] would also ensure that the Map is only rehashed when the entries become greater than 3.


I would imagine that using loadFactor and initialCapacity may provide performance close to Flat3Map. It seems that Sun put them there for situations when the number of entries is known - the same situation you're in.


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to