PicoContainer
  1. PicoContainer
  2. PICO-395

Optimization for DefaultPicoContainer.getInstance

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.14.1
    • Fix Version/s: 2.15
    • Component/s: PicoContainer (Java)
    • Labels:
      None
    • Number of attachments :
      1

      Description

      This method

      DefaultPicoContainer.getInstance()

      currently does this

      getModifiableComponentAdapterList().contains(componentAdapter);

      which involves scraping over an array. This is rather slow for a big container and is proving to be a bottleneck in our application.

      If you have n containers being instantiated then you'll do contains n times on a list o which will be o(n^2) calls to equals.

      Two simple fixes spring to mind:

      • Keep the component adapters in a set instead - if you use a linked hash set then you'd get exactly the same iteration order but contains() will be fast.
      • Use the keyToAdapterCache map instead like so:
        getComponentKeyToAdapterCache().get(componentAdapter.getComponentKey()) == componentAdapter

      A more involved alternative might be to admit that a given ComponentAdapter needs to know its parent PicoContainer and hence keep a back-reference so you could do componentAdapater.getPicoContainer() == this.

        People

        • Assignee:
          Paul Hammant
          Reporter:
          Chris Simmons
        • Votes:
          1 Vote for this issue
          Watchers:
          3 Start watching this issue

          Dates

          • Created:
            Updated:
            Resolved: