PropertyUtils性能 [英] PropertyUtils performance

查看:48
本文介绍了PropertyUtils性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,我需要遍历对象图并挑选出特定的属性值.我的原始解决方案缓存了属性名称的链接列表,这些属性名称需要应用才能从对象图中的A点到达B点.然后,我使用apache commons PropertyUtils 进行迭代通过调用getProperty(Object bean,String name)的链接列表,直到到达B点为止.

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.

我的问题是,与可能为每个步骤处理Method对象相比,此方法将如何执行.在阀盖下,propertyUtils在做什么?它会产生很多反射/沉重负担吗?

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?

推荐答案

您不需要手动横切图,因为新版本的commons beanutils还支持诸如bean1.prop1.prop2之类的表达式.

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

关于性能,如果每个表达式只执行一次,则propertyutils实现很好,因为一定程度的反射是绝对必要的.

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.

如果您多次使用该表达式,则可以看看支持编译表达式"的OGNL.

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

这篇关于PropertyUtils性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆