[ https://issues.apache.org/jira/browse/HADOOP-1017?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12473791 ]
Doug Cutting commented on HADOOP-1017: -------------------------------------- A few more thoughts: - should constructorCache be 'static final', and hence named CACHE, all-caps? - the values of the WeakHashMap are of type Constructor, each which references its Class, the key. According to http://java.sun.com/j2se/1.5.0/docs/api/java/util/WeakHashMap.html, if values reference the keys, entries will never by collected. So we should either just use a HashMap, and not permit these to be collected, which is probably fine, or change the values to be WeakReferences to the constructors. > Optimization: Reduce Overhead from ReflectionUtils.newInstance > -------------------------------------------------------------- > > Key: HADOOP-1017 > URL: https://issues.apache.org/jira/browse/HADOOP-1017 > Project: Hadoop > Issue Type: Improvement > Components: util > Reporter: Ron Bodkin > Attachments: cacheCtor.patch, ReflectionUtils.patch.txt, > TestReflectionUtils.java > > > I found that a significant amount of time on my project was being spent in > creating constructors for each row of data. I dramatically optimized this > performance by creating a simple WeakHashMap to cache constructors by class. > For example, in a sample job I find that ReflectionUtils.newInstance takes > 200 ms (2% of total) with the cache enabled, but it uses 900 ms (6% of total) > without the cache. -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.