Search code examples
javascriptgwtjsni

Any downsides to excessively using JSNI calls in GWT?


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...


Solution

  • 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).