Funtime
Funtime

Reputation: 2624

GWT optimisation

Will first line work faster than second line in GWT? Is there difference of translation this code in JavaScript in different GWT versions?

ArrayList<String> list = new ArrayList<String>(); 

List<String> list = new ArrayList<String>(); 

As i know if i will write declearet type List, JavaScript performance will be worst, because will check is this List LinkedList or ArrayList or other type of list. Is it right?

Will it improve performance if i will write

ArrayList<String> list = new ArrayList<String>(); 

instead of

List<String> list = new ArrayList<String>(); 

?

Upvotes: 0

Views: 519

Answers (3)

Andreas K&#246;berle
Andreas K&#246;berle

Reputation: 110922

There is no difference between them, both converted to a non typed JavaScript array. After all you could also use String[], it would made no difference in the compiled code.

Upvotes: 0

mabn
mabn

Reputation: 2523

I'm not sure, but I think that when you use List<...> as a return type of a service method the compiler will have to compile all List implementations so it will generate larger code then if you used ArrayList

Upvotes: 0

BobV
BobV

Reputation: 4173

Both lines are equivalent. The GWT compiler performs an optimization called "type tightening." You can watch how the compiler optimizes a particular method by defining a Java environment property when you compile a module:

-Dgwt.jjs.traceMethods=Hello.onModuleLoad:OtherClass.otherMethod

From the JProgram source:

The format to trace methods is a colon-separated list of "className.methodName", such as "Hello.onModuleLoad:Foo.bar". You can fully-qualify a class to disambiguate classes, and you can also append the JSNI signature of the method to disambiguate overloads, "Foo.bar(IZ)".

Upvotes: 4

Related Questions