PropertyUtils performance

别来无恙 提交于 2021-02-08 02:35:11

问题


I have a problem where i need to walk through an object graph and pick out a particular property value. My original solution caches a linked list of property names that need to be applied in order to get from point A to point B in the object graph. I then use apache commons PropertyUtils to iterate through the linked list calling getProperty(Object bean, String name) until i have reached point B.

My question is around how this will perform compared to perhaps cahing the Method objects for each step. What is propertyUtils doing under the bonnet? Is it doing a lot of reflection / heavy lifting?


回答1:


You don't need to transverse manually the graph because new versions of commons beanutils also support expressions like bean1.prop1.prop2.

About the performance if you only execute once each expression the propertyutils implementations is fine, because some degree of reflection is absolutely necesary.

You can make a more real performance improvment if each expression is called several times. Then caching the final methods to execute can improve the result because you do the big reflection only one time for expression.

If you use the expression several times you can take a look to OGNL that support "compiled expressions".



来源:https://stackoverflow.com/questions/2228542/propertyutils-performance

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!