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
Repository Revision Date User Message
ASF #416980 Sun Jun 25 03:13:17 UTC 2006 niallp CHAIN-32 Improve instantiation performance of ContextBase subclasses. Thanks to Joshua Graham.
Files Changed
MODIFY /jakarta/commons/proper/chain/trunk/src/java/org/apache/commons/chain/impl/ContextBase.java
MODIFY /jakarta/commons/proper/chain/trunk/xdocs/changes.xml

Niall Pemberton added a comment - 25/Jun/06 10:22 AM
Thanks for the patch - I applied a slight variation on what you suggested since removing the calls to the "eliminate" method means that there will always be a pd array of at least 2 and your implementation resulted in unnecessarily creating an empty Map when there were no properties.

Niall Pemberton made changes - 25/Jun/06 10:22 AM
Field Original Value New Value
Assignee Niall Pemberton [ niallp ]
Status Open [ 1 ] Resolved [ 5 ]
Resolution Fixed [ 1 ]
Fix Version/s 1.2 [ 12311963 ]
Henri Yandell made changes - 02/Jan/08 07:01 AM
Status Resolved [ 5 ] Closed [ 6 ]