You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Fred Dushin <fr...@dushin.net> on 2008/04/29 16:16:31 UTC

HashHappy

Is there a reason hashed collections are used, almost exclusively, in  
CXF?  Even in cases where collections are predictably small, Hash(Maps| 
Sets) almost always win out over their sortable cousins in the  
java.util namespace, and this, even when the keys are sortable.

Is there a technical reason for this?  A personal preference?

I've done some performance comparisons between the 2, and for small  
collections, the log(n) lookup doesn't make a difference at all.  So  
for small collections, I'd think CXF might benefit from the relatively  
smaller memory footprint of sortable collections.  We'd also benefit  
from more predictable behavior, as ordering is deterministic, with  
sortable collections.

The same goes for ArrayLists vs LinkedLists, BTW.

Just wondering...

-Fred

Re: HashHappy

Posted by Daniel Kulp <dk...@apache.org>.
On Tuesday 29 April 2008, Fred Dushin wrote:
> Is there a reason hashed collections are used, almost exclusively, in
> CXF?  Even in cases where collections are predictably small,
> Hash(Maps| Sets) almost always win out over their sortable cousins in
> the java.util namespace, and this, even when the keys are sortable.
>
> Is there a technical reason for this?  A personal preference?

Depends on the location in the code.   One reason for using a hash based 
map is that there exists the ConcurrentHashMap that is a drop in 
replacement when thread concurrency is required.  Likewise, there is a 
CopyOnWriteArrayList for the ArrayList flip.   There aren't any 
conncurrent versions of the SortedSet/Map things.  (they were added in 
Java 1.6, but not available in Java 1.5) 


> I've done some performance comparisons between the 2, and for small
> collections, the log(n) lookup doesn't make a difference at all.  So
> for small collections, I'd think CXF might benefit from the relatively
> smaller memory footprint of sortable collections.  We'd also benefit
> from more predictable behavior, as ordering is deterministic, with
> sortable collections.
>
> The same goes for ArrayLists vs LinkedLists, BTW.

Actually, that really does depend.   In most cases, and ArrayList uses 
less memory than a LinkedList, especially if we set a "smart" initial 
size. 

> Just wondering...

Probably just preference and maybe a small bit of "consistency" thrown in 
for good measure.  


-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: HashHappy

Posted by Daniel Kulp <dk...@apache.org>.
On Tuesday 29 April 2008, Fred Dushin wrote:
> Performance measurements would certainly be in order, if a change were
> to occur.
>
> What I'm more concerned about is flushing out any ordering assumptions
> in collections that are inherently unordered.  That, and
> reproducibility of errors on Mac/Windows/Linux/etc

Actually, that brings up the other issue....  The LinkedHashMap and 
LinkedHashSet collections that provide order based on insertion order.   

Thus, for each replacement, you would need to determine what IS the order 
supposed to be if an order is supposed to be maintained.   If no order 
is specified, then it would need to drop to performance comparisons to 
see if a sorted version is better than a hash version.

Dan


> On Apr 29, 2008, at 10:26 AM, Benson Margulies wrote:
> > Fred,
> >
> > I'd be happy to profile any test case in which you think such a case
> > would
> > help. I'm not really spun up on profiling for working set as opposed
> > to CPU,
> > but I'm game to try.
> >
> > --benson



-- 
J. Daniel Kulp
Principal Engineer, IONA
dkulp@apache.org
http://www.dankulp.com/blog

Re: HashHappy

Posted by Fred Dushin <fr...@dushin.net>.
Performance measurements would certainly be in order, if a change were  
to occur.

What I'm more concerned about is flushing out any ordering assumptions  
in collections that are inherently unordered.  That, and  
reproducibility of errors on Mac/Windows/Linux/etc

On Apr 29, 2008, at 10:26 AM, Benson Margulies wrote:

> Fred,
>
> I'd be happy to profile any test case in which you think such a case  
> would
> help. I'm not really spun up on profiling for working set as opposed  
> to CPU,
> but I'm game to try.
>
> --benson


Re: HashHappy

Posted by Benson Margulies <bi...@gmail.com>.
Fred,

I'd be happy to profile any test case in which you think such a case would
help. I'm not really spun up on profiling for working set as opposed to CPU,
but I'm game to try.

--benson