Uploaded image for project: 'Commons Chain'
  1. Commons Chain
  2. CHAIN-32

Improve instantiation performance of ContextBase subclasses

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Trivial
    • Resolution: Fixed
    • 1.0
    • 1.2
    • None
    • None
    • Any

    Description

      Noted that iteration through pd[] array thrice: twice to eliminate() the "empty" and "class" entries, and lastly to add each remaining entry to the descriptors map. The first two iterations each include costly array copies.

      Guessed that two if name.equals checks in the third iteration would tend to be much quicker (especially for Beans with many properties). Did some quick performance checks to verify that this is the case - it's enough of a change to warrant a small refactor.

      Here's a revised initialize(). You can thus remove the eliminate() method...

      // Retrieve the set of property descriptors for this Context class
      try

      { pd = Introspector.getBeanInfo (getClass()).getPropertyDescriptors(); }

      catch (IntrospectionException e)

      { pd = new PropertyDescriptor[0]; // Should never happen }

      // Initialize the underlying Map contents
      if (pd.length > 0) {
      descriptors = new HashMap();
      for (int i = 0; i < pd.length; i++) {
      String name = pd[i].getName();
      if ("class".equals(name) || "empty".equals(name))

      { // skip getClass() and isEmpty(); }

      else

      { descriptors.put(name, pd[i]); super.put(name, singleton); }

      }
      }
      }

      Attachments

        Activity

          People

            niallp Niall Pemberton
            jagraham Joshua Graham
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: