| Summary: | Performance: StateHelperImpl: creating of map/set with initial capacity causes resizing | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Equinox | Reporter: | Radoslav Ivanov <radoslav.ivanov> | ||||
| Component: | Framework | Assignee: | Lazar Kirchev <l.kirchev> | ||||
| Status: | RESOLVED FIXED | QA Contact: | |||||
| Severity: | minor | ||||||
| Priority: | P3 | CC: | l.kirchev, tjwatson | ||||
| Version: | unspecified | ||||||
| Target Milestone: | 3.7 M6 | ||||||
| Hardware: | PC | ||||||
| OS: | Windows 7 | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Radoslav Ivanov
Lazar would you be willing to provide a patch? (In reply to comment #1) > Lazar would you be willing to provide a patch? Yes, I will check the code and provide a patch. Created attachment 187804 [details]
Patch for collections initialization
Here is a possible patch. I removed the initial capacity from the creation of HashMap and HashSet. I think it is better to leave the default initial capacity since we cannot know in advance approximately how much elements will be added to the collection. This may vary largely. Probably we still will have array copies because the actual size could be much more than the default initial capacity of the collection (which is 16), but how much more? 100? 500? We may have a framework with just a handful of bundles, but may have an enterprise installation with hundreds of bundles. Any suggestions here?
Probably we could try as a heuristic to take the number of bundles in the State and use as initial capacity for the result the number of bundles multiplied by some factor, representing an average expected number of exported packages per bundle, but even this is hard to predict. Yet, this may cause less array copies.
As for the HashSet, it was initialized with 1 because it is expected that one package will be exported by only one bundle. But this is not always the case - when we have several different versions of a bundle, then all of them could export packages with the same name.
(In reply to comment #3) Thanks for the analysis Lazar. I think we should release your patch and not try anything more complicated. I released the patch, but I question if you will actually see any measurable performance improvements here. Especially for the case where we have a HashSet containing the packages. This actually will likely use more memory, for what I think is the common case, when there is only one version of a package available at runtime. |