Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT collections performance and recommended practices

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

like image 611
Javier Ferrero Avatar asked Feb 26 '23 06:02

Javier Ferrero


1 Answers

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.

like image 93
Jason Hall Avatar answered Mar 06 '23 14:03

Jason Hall