> 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?
Well we certainly have lots of other collections/maps that are tweaked in
other ways, for fast reads and slow writes, for validation, for observing
changes. One that handles small sizes well seems to be a good fit.

One variation would be to say that the map has a fixed size of 3 above which
it cannot go. It might make things clearer as to when to use it, but less
flexible.

> 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.
These parameters wouldn't be ideal. The initial allocation size of the
HashMap goes down from 120 bytes to 72 bytes (close to the 56 bytes).
However the Flat3Map retains a _constant_ size as it is updated with no
object creation.

Adding and removing from a HashMap always creates an Entry object at a cost
of 24 bytes and significant time (both creation and gc) for each new entry.

In my performance test, HashMap(3, 1) performs basically the same as
HashMap(), as I expected.

In some degree, the question is whether the gc time is proportional to the
number of objects it collects. And if it is, then Flat3Map is a good design,
and would probably scale to larger sizes.

A variation on the design is to store the keys and values in two parallel
Object arrays rather than Entry objects. Again this should have a
significant impact in avoiding object creation. I believe this might require
an 'open' hashing technique. Anyone know anything about this or have an
example implementation?

Stephen


> > 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]



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

Reply via email to