4
votes

Might seem like a naive question, but is there any obvious downside (performance wise) to using alot JSNI instead of just sticking to pure GWT?

I ask because as i work with GWT, i find myself having to deal with very specific requirements that are best approached by using mature Javascript libraries...

2

2 Answers

5
votes

The only downside is about using third-part libs: you won't benefit from the dead-code pruning done by the GWT compilation (that is, unless you somehow wrap the lib as JSNI).

Actually, there's another one: because GWT will only optimize your JS code, you won't benefit from further optimizations that could have been done had it been written in Java. This is because Java is a statically-typed language.

Other than that, no, JSNI has no negative impact on performances (in DevMode it can be quite the contrary actually: the more you switch from Java to JS and/or Js to Java, the slower it becomes; but that's only for DevMode, which in turn is going to be kind of deprecated in the coming months).

1
votes

I think JSNI code is slower in development mode. However, dev mode is apparently supposed to be replaced with super draft mode soonish, see https://plus.google.com/110412141990454266397/posts/iqXo5AyHkyd

Also, I am not sure to which extent GWT is able to analyze and optimize pure Javascript code. When compiling pure Java, GWT does a lot of inlining and other optimizations.

Another issue may be the extra round trip for loading the libraries.

Depending on the complexity of the library API (i.e. if you would need to wrap tons of classes), it may be simpler to convert a comparable pure Java library to GWT. But that obviously does not work for UI libraries or other libraries heavily depending on parts of the Java runtime not covered by GWT.

So if there are existing mature Javascript libraries that fit your purpose, it is probably best to wrap them in JSNI and go ahead as you suggest.

The JSNI boundary itself does not create any extra runtime overhead.