PropertyUtils 性能

发布于 2024-08-21 09:09:03 字数 396 浏览 5 评论 0原文

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

我的问题是,与可能为每个步骤缓存 Method 对象相比,这将如何执行。 propertyUtils 在后台做什么?它是否做了很多反射/繁重的工作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灼痛 2024-08-28 09:09:03

您不需要手动横切图表,因为新版本的 commons beanutils 还支持像 bean1.prop1.prop2 这样的表达式。

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

如果多次调用每个表达式,您可以实现更实际的性能改进。然后缓存要执行的最终方法可以改善结果,因为您只为表达式执行一次大反射。

如果您多次使用该表达式,您可以查看支持“编译表达式”的 OGNL。

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".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文