Java 对象创建与字符串解析
我正在努力将一个以 JSP 为中心的项目迁移到使用 Velocity。在许多地方,JSP 页面只是简单地解析字符串来显示各种内容。这使得JSP明显变得非常丑陋并且难以维护。
我已经修改了此类的控制器来为我完成这项工作(即创建 POJO 列表),然后使用速度迭代各个部分。我有预感,这将会带来很大的阻力。
我意识到创建对象会带来开销,但它使我们的页面更容易调试、编写和使用。除此之外,它将 UI 与后台发生的核心逻辑分开。更不用说我们的应用程序服务器很无聊。数据库痛苦地皱起眉头。我们将看到用户数量增加十倍(这可能就是为什么它最初被开发来解析 JSP 中的字符串并跳过对象创建)——这对我来说是过早优化的味道。
有哪些进一步的论据来支持我的主张,即我们应该承担与对象创建相关的成本?
I'm working on migrating a project which is very JSP-centric to using Velocity. In many places the JSP pages were simply parsing strings to display various things. This makes the JSP very ugly and difficult to maintain obviously.
I have modified the Controller for this class to do this work for me (i.e. creating a List of POJOs), then iterating over the pieces using velocity. I have a feeling that it's going to come with heavy resistance.
I realize that creating the Object comes with overhead, but it makes our pages much easier to debug, write and use. Besides the fact it separates the UI from the core logic of what is occurring in the background. Not to mention our appservers are BORED. The database is wincing in pain. We are to see a tenfold increase in users (which could be why it was initially developed to parse the strings in the JSP & skip the object creation) -- this smells to me of premature optimization.
What are further arguments to support my claim that we should eat the cost associated with the object creation?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对象创建很便宜。非常便宜。现代计算机速度很快。非常快。
做一些简单的分析。查看创建一百万个 POJO 需要多长时间。会很快的。
Object creation is cheap. Very cheap. And modern computers are fast. Very fast.
Do some simple profiling. See how long it takes to create a million of your POJOs. It'll be quite quick.
维护——大部分资金都花在维护软件而不是开发上。如果您使某些东西易于维护和扩展,那是一件幸事。
在这个社区中,进行任何过早的优化通常都会受到反对。您运行在什么样的硬件上?我认为服务器可以处理您的工作负载...我倾向于首先使其正常运行,然后找到瓶颈的想法。当您分析对象时,您可能会发现对象创建并不是最大的问题。
Maintenance - most dollars are spent maintaining software vs. developing. If you make something easy to maintain and extend, it's a blessing.
It's generally frowned upon in this community to do any premature optimization. What kind of hardware are you running on? I imagine servers can handle your workload... I tend to like the idea of making it work well first, and then finding bottle necks. You might find that object creation isn't the biggest problem when you profile it.