有没有使用Bloch的Builder Pattern获得记忆和性能? [英] Is there a memory and performance hit taken from using Bloch's Builder Pattern?

查看:130
本文介绍了有没有使用Bloch的Builder Pattern获得记忆和性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

与创建只有构造函数的对象相比,内存和性能的使用情况如何?



这里的用法是创建一个 Set< Object> List< Object& 可能包含百万加条目,我关心使用Bloch的Builder Pattern的开销。我以前一直使用它,但从来没有在这个大范围内。



参考: 项目2:在面对许多构造函数参数 时考虑构建器,转载于 创建和销毁Java对象:第1部分 ,摘自 有效的Java第二版 作者:Joshua Bloch。

解决方案

您有额外的Builder对象,在创建对象后被丢弃。所以你可能会对内存使用和速度有一些影响。但是,Java-VM非常强大的优化,特别是Server-VM(java -server),因此VM可以完全完成构建构建器。所以我的建议是你应该衡量真正的影响(一如往常,如果你关心性能),并决定影响是否太大。


What is the memory and performance usage compared to creating a object with only a constructor?

The usage here is in creating a Set<Object> or List<Object> that may contain million plus entries and I am concerned with the overhead of using Bloch's Builder Pattern. I have used it in the past, but never in this large of a scope.

Reference: Item 2: Consider a builder when faced with many constructor parameters, reprinted in Creating and Destroying Java Objects: Part 1, excerpted from Effective Java Second Edition by Joshua Bloch.

解决方案

You have the additional Builder-object, that is discarded after the creation of the object. So you may have some impact on memory-usage and speed. But the Java-VM does optimize very strongly, especially the Server-VM (java -server), so the VM may optimize away the builder completely. So my suggestion is you should measure the real impact (as always if you care about performance) and decide if the impact is too big.

这篇关于有没有使用Bloch的Builder Pattern获得记忆和性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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