在 GWT 中处理集合的最佳方法和/或推荐实践是什么,特别是在寻求性能时?
到目前为止我找到的选项有:
-
JRE 模拟集合。最
对于 Java 开发人员来说很自然,但是,
用 GWT 团队的话来说“不是一个理想的匹配
对于内部运行的限制
浏览器,尤其是移动浏览器
浏览器”。性能比较
可以在此处和此处
-
GWT 轻量级集合。
在其他改进之间,他们
承诺携带最小尺寸
编译脚本和绝对最大值
速度。然而还没有任何消息
关于此项目 7 个月。
-
Guava 库安全吗
在 GWT 中使用 Guava 吗?如果是的话,是吗
带来真正的性能提升吗?
还有其他选择吗?
非常感谢
What is the best way and/or recommended practices for working with collections in GWT, specially if looking for performance?
The options I have found so far are:
-
JRE emulated collections. The most
natural way for a Java developer but,
in GWT team words "not an ideal match
for the constraints of running inside
browsers, especially mobile
browsers". A performance comparaison
can be found here and here
-
GWT Lightweight Collections.
Between other improvements they
promised to bring minimum size of
compiled script and absolute maximum
speed. However there are no news
regarding this project for 7 months.
-
Guava Libraries Is it safe to
use Guava in GWT? If so, does it
brings real performance improvement?
Any other alternatives?
Many thanks
发布评论
评论(2)
如果您正在寻找浏览器上绝对最佳的性能,您应该使用诸如轻量级集合之类的东西 - 仅原生 JS 数组和映射,以及所有包含的对象作为 JavaScriptObjects(覆盖类型)。
然而,这将严重限制您的编码效率,因为它们根本不像 JRE 集合那样易于使用。没有
contains()
,没有增强的 for 循环,没有 Java 的优点。毕竟,“Java 的优点”大概就是您使用 GWT 而不是 JS 进行编程的原因。Guava 并不旨在为 GWT 应用程序带来任何特定的效率优势,它主要只是提供更简单的编码体验,偶尔还会进行一些您可能没有考虑到的微小优化。 Guava 没有针对 GWT 进行优化,它仅在 GWT 上可用。
所以,这取决于你。如果您想方便地使用常规 Java 集合,则应该使用 Guava。如果您想要绝对最快的性能,请在本机集合中执行所有操作。
If you're looking for absolute optimal performance on the browser, you should use something like Lightweight Collections -- native JS arrays and maps only, and all contained objects as JavaScriptObjects (overlay types).
However, this will severely limit your coding efficiency, since they aren't at all as easy to use as JRE collections. There is no
contains()
, no enhanced for loops, none of the niceties of Java. And after all, "the niceties of Java" are presumably why you're programming in GWT and not JS.Guava doesn't aim to bring any particular efficiency benefits to a GWT app, it mostly just provides a simpler coding experience, and occasionally a tiny optimization here and there that you may not have considered. Guava is not optimized for GWT, it's merely available on GWT.
So, it's up to you. If you want to have the convenience of using regular Java collections, you should use Guava. If you want the absolute fastest performance, do everything in native collections.
同意之前的答案并提供一些其他详细信息:
GWT 轻量级集合仅设计为客户端。如果您想使用 RPC 机制传输这些内容,您可能会遇到异常。
另一种加速 JavaScript 的方法是使用数组而不是集合,这样既可以进行传输也可以进行处理。数组更接近 JavaScript 类似物,并且出于兼容性目的,GWT 不会编译太多包装代码。
也不期望 Guava 带来任何性能优势。
Agree with previous answer and providing some additional details:
GWT Lightweight collections designed to be client-side only. If you will want to transfer those using RPC mechanism you will likely end in the exception.
Another approach to speed up your JavaScript is to use Arrays instead of Collections where it is possible both for transport and processing. Arrays are closer to its JavaScript analogues and GWT does not compile-in too much wrapping code for compatibility purposes.
Would not expect any performance benefits from Guava as well.