简体   繁体   English

在GWT中过度使用JSNI调用的任何缺点?

[英]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? 可能看起来像一个天真的问题,但使用很多JSNI而不仅仅是坚持纯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... 我问,因为当我使用GWT时,我发现自己必须处理通过使用成熟的Javascript库最佳接近的非常具体的要求......

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). 唯一的缺点是使用第三方库:你不会受益于GWT编译所做的死代码修剪 (也就是说,除非你以某种方式将lib包装为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. 实际上,还有另外一个:因为GWT只会优化你的JS代码,所以如果用Java编写的话,你不会受益于进一步的优化。 This is because Java is a statically-typed language. 这是因为Java是一种静态类型的语言。

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). 除此之外,不,JSNI对性能没有负面影响(在DevMode中它实际上可能完全相反:你从Java切换到JS和/或Js到Java越多,它变得越慢;但这只适用于DevMode,这反过来会在未来几个月内被弃用 )。

I think JSNI code is slower in development mode. 我认为JSNI代码在开发模式下速度较慢。 However, dev mode is apparently supposed to be replaced with super draft mode soonish, see https://plus.google.com/110412141990454266397/posts/iqXo5AyHkyd 但是,开发模式显然应该很快被替换为超级草案模式,请参阅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. 此外,我不确定GWT能够在多大程度上分析和优化纯Javascript代码。 When compiling pure Java, GWT does a lot of inlining and other optimizations. 在编译纯Java时,GWT会进行大量的内联和其他优化。

Another issue may be the extra round trip for loading the libraries. 另一个问题可能是加载库的额外往返。

Depending on the complexity of the library API (ie if you would need to wrap tons of classes), it may be simpler to convert a comparable pure Java library to GWT. 根据库API的复杂性(即,如果需要包装大量的类),将类似的纯Java库转换为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. 但这显然不适用于UI库或其他库,严重依赖于GWT未涵盖的Java运行时部分。

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. 因此,如果存在适合您目的的成熟Javascript库,最好将它们包装在JSNI中并按照您的建议继续进行。

The JSNI boundary itself does not create any extra runtime overhead. JSNI边界本身不会产生任何额外的运行时开销。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM