Bug 185230 - Hash collections in StateHelperImpl have too small, static initial capacity
Summary: Hash collections in StateHelperImpl have too small, static initial capacity
Status: RESOLVED WONTFIX
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Framework (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: equinox.framework-inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: performance
Depends on:
Blocks:
 
Reported: 2007-05-02 17:10 EDT by Dave Stevenson CLA
Modified: 2010-11-02 16:31 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Stevenson CLA 2007-05-02 17:10:57 EDT
The StateHelperImpl class in org.eclipse.osgi.internal.resolver has three instances where collections are created with initial capacity 11:
 
	Map result = new HashMap(11);

	HashSet result = new HashSet(11);

in methods getExportedPackageMap(), getGenericsMap(), and getUnsatisfiedLeaves().

When the state contains a large number of bundles (I am running scenarios with ~4000 bundles) performance suffers very significantly due to rehashing. For example, in getGenericsMap() where the result grows to over 6000 elements, the call takes over 30 minutes.

The initial capacity of the these collections should be computed based on the number of bundles in the state.
Comment 1 Dave Stevenson CLA 2007-05-02 17:13:51 EDT
Added performance keyword.
Comment 2 Jeff McAffer CLA 2007-05-02 22:59:18 EDT
Do have to watch the converse.  For example, in "normal" circumstances there tend to be very few unsatisfied leaves.
Comment 3 Thomas Watson CLA 2007-05-03 10:14:58 EDT
I think the real cost is the call to isResolvable(GenericSpecification) from getUnsatisfiedConstraints(BundleDescription) which is called for each bundle passed to getUnsatisfiedLeaves(State, BundleDescription[])

The method isResolvable(GenericSpecification) will reconstruct the Map of generics each call.  This will quickly get out of hand if you have lots of BundleDescriptions with generic constraints.

Pascal, is the provisioning work is using generic constraints extensively?  I think you are mapping the constraints to generics, right?  If so I can see how this has just now surfaced as an issue.
Comment 4 Thomas Watson CLA 2007-05-03 11:55:34 EDT
I noticed the class org.eclipse.equinox.prov.resolution.ResolutionHelper is calling StateHelper.getUnsatisfiedLeaves for every BundleDescription that got installed individually.  Why is this done for each individual BundleDesciption, also should it not only do this if the BundleDescription is unresolved?

Is there any way you can pass all the added bundles in a single call to StateHelper.getUnsatisfiedLeaves?  To improve performance in this area we should move the hashing to StateImpl so that we do not have to keep reconstructing the Maps with each call to the static StateHelper methods.
Comment 5 Thomas Watson CLA 2010-11-02 16:31:04 EDT
No plans to address this.