GWT already optimizes a HashMap<String, ...> similar to what you have 
implemented. You can see this in [1] and the specialized methods if the key 
type is String.class. Also ArrayList is backed by a native JS array. Of 
course GWT carries some overhead because it emulates the full Java API but 
because it's already quite optimized you don't see a huge improvement when 
switching from Java to JavaJsCollection. The largest improvement is on IE 
but IMHO thats not a surprise.

StringBuilder in GWT is just appending strings and does not use any buffer 
array like in real Java. It is basically s += toAppend which is pretty fast 
in browsers.

The biggest difference I see is that the Java / JavaJsCollection version 
use String.toCharArray() which actually creates a new array, walks the 
string and fills the array. It is probably faster to do

for (int i = 0; i < string.length(); i++) { 
  char c = string.charAt(i); 
  ....
}

because Java's String.charAt(i) is directly mapped to JavaScript's 
String.charCodeAt(i) (see [2]) and you avoid the char array creation.


[1] 
https://gwt.googlesource.com/gwt/+/master/user/super/com/google/gwt/emul/java/util/AbstractHashMap.java
[2] 
https://gwt.googlesource.com/gwt/+/master/user/super/com/google/gwt/emul/java/lang/String.java#609


-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to