[jbosscache-dev] Immutables.immutableSetCopy

Brian Stansberry brian.stansberry at redhat.com
Wed Aug 19 18:16:31 EDT 2009


This method looks quite inefficient for its actual usage.

A look in the IDE shows its used by UnversionedNode.getChildrenNames() 
and getKeysDirect(). Those pass either a ConcurrentHashMap$KeySet, a 
FastCopyHashMap$KeySet, Collections$EmptySet or 
Collections$SingletonSet.  The attempted optimizations (some of which 
involve reflection) in immutableSetCopy can handle non of those and 
eventually the HashSet copy constructor gets called.

A profiling run showed 22 invocations of UnversionedNode.getKeysDirect() 
took 3,804 microseconds, of which 3,563 was in immutableSetCopy.  789 of 
that was in the new HashSet(toCopy) call; the rest was basically wasted.

Any reason I shouldn't just turn this into a new HashSet(toCopy) call?

-- 
Brian Stansberry
Lead, AS Clustering
JBoss by Red Hat


More information about the jbosscache-dev mailing list