PropertyUtils 性能 [英] PropertyUtils performance

查看:22
本文介绍了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天全站免登陆