Issue Details (XML | Word | Printable)

Key: CHAIN-32
Type: Improvement Improvement
Status: Closed Closed
Resolution: Fixed
Priority: Trivial Trivial
Assignee: Niall Pemberton
Reporter: Joshua Graham
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Commons Chain

Improve instantiation performance of ContextBase subclasses

Created: 24/Jun/06 08:22 PM   Updated: 02/Jan/08 07:01 AM
Return to search
Component/s: None
Affects Version/s: 1.0
Fix Version/s: 1.2

Time Tracking:
Not Specified

Environment: Any

Resolution Date: 25/Jun/06 10:22 AM


 Description  « Hide
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); }
}
}
}



 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
No work has yet been logged on this issue.