JavaFX 中 WebView 的性能 [英] Performance of WebView in JavaFX

查看:37
本文介绍了JavaFX 中 WebView 的性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 HTML5 UI 和一个 Java 后端,并希望避免在纯 Java 中重建 HTML ui,所以我的想法是运行本地网络服务器并使用 web 视图在本机"窗口中呈现它.解决方案似乎是使用可以嵌入到 Swing 中的 JavaFX WebView.从理论上讲,这听起来很棒(尤其是因为他们声称使用 WebKit,它对我在 Chrome/Safari 中的 UI 具有明显更好的性能).

它有效,但是:性能非常糟糕.比 Chrome、Safari(甚至更慢的 Firefox)中的同一件事慢几个数量级.它实际上无法使用(我的 UI 大量使用了 JQuery/JS).顺便说一句,我正在使用 中的代码这个帖子.

问题是:

  1. 有人可以借鉴我的经验吗?我只是做错了什么还是这是由 JavaFX 引起的,因此是正常的"?

  2. 有什么更好的想法来实现这一目标吗?我目前只是启动系统浏览器,它可以工作但不是很好(看起来不像集成).

解决方案

我使用了很多 WebView,通常性能非常好,非常好用.

  • Html5 合规性很好.
  • JavaScript 性能各不相同,但我发现根据 Google 的 V8 基准测试(Chrome 可能针对该基准进行了调整),它的速度大约是最新版本 Chrome 的三分之一.
  • 渲染性能似乎不是什么大问题.
  • 非常密集的 HTML Web 应用程序(例如 Chrome 实验库中的某些应用程序)的启动速度不如其他一些浏览器.
  • WebGL 不受支持,因此退回到从 WebGL 软件渲染图形的网站速度要慢得多.

我对 WebView 的最大问题是它在尖端功能和密集使用方面不如其他浏览器那么稳定,但实际上并没有任何严重的性能问题.

以下是一些基准统计数据(使用的 WebView 版本来自 JavaFX 2.2 build 9):

合规性

运行 html5 测试以测试 html5 合规性(总分 500):

<前>Chrome 19 402 + 13 奖励积分Firefox 12 345 + 9 积分WebView 2.2b9 296 + 7 奖励积分IE 9.0.6 138 + 5 奖励积分

运行 acid3 测试,webview 的得分与其他测试浏览器相同,为 100/100,但是,与 IE9 一样,最终渲染具有轻微瑕疵.

Javascript

Sunspider Javascript 基准测试(越低越好):

<前>IE 9.0.6 146.7 毫秒铬 19 151.5ms火狐 12 185.8 毫秒WebView 2.2b9 199.5ms

Google V8 Javascript 基准测试(越高越好):

<前>铬 19 15323火狐 12 9557网络视图 2.2b9 5145浏览器 9.0.6 3661

Mozilla Kraken Javascript 基准测试(越低越好):

<前>铬 19 2416.8ms火狐 12 2112.9 毫秒WebView 2.2b9 7988.9msIE 9.0.6 9403.0 毫秒

密集画布

旋转3D佛(越高越好):

<前>铬 19 60fps火狐 12 43fpsIE 9.0.6 16fpsWebView 2.2b9 7fps

JQuery

JQuery 测试套件执行(越低越好):

<前>铬 19 21826 毫秒WebView 2.2b9 22742 毫秒火狐 12 23554 毫秒IE 9.0.6 28247 毫秒

基于上述基准测试(在我的 Windows 7 桌面上运行),只要 WebView 对您来说足够稳定且功能足够,那么 WebView 与其他浏览器的性能相比应该不是问题(只要您的应用程序没有功能很多 3D 旋转的佛陀...... :-).

更新

正如 uta 的回答所述,JavaFX 2.2 的 Win 32 位版本已打开 JavaScript JIT 编译器,关闭对于 JavaFX 2.2 的 Win 64 位构建.这意味着在运行 64 位 JavaFX 版本与 32 位 JavaFX 版本时,WebView JavaScript 基准测试明显变慢(通常慢 4 到 5 倍).

I have a HTML5 UI and a Java backend and want to avoid rebuilding the HTML ui in plain java, so my idea was to run a local webserver and use a webview to render it in a "native" window. The solution seems to be to use a JavaFX WebView which can be embedded in swing. On the paper it sounds great (especially since they claim to use WebKit which has a significantly better performance for my UI in Chrome / Safari).

It works, but: the performance is INCREDIBLY BAD. Orders of magnitude slower than the same thing in Chrome, Safari (or even the slower Firefox). It is literally unusable (my UI makes quite heavy use of JQuery / JS). Btw, I am using the code from this post.

The question is:

  1. Can anybody second my experience? Am I simply doing something wrong or is this caused by JavaFX and thus "normal"?

  2. Any better idea how to achieve this? I am currently simply firing up the system browser which works but is not as nice (does not look as integrated). 

解决方案

I have used WebView quite a bit and usually the performance was perfectly fine and very usable.

  • Html5 compliance is good.
  • JavaScript performance varies but I found it about one third the speed of a recent version of Chrome according to Google's V8 benchmark (which Chrome is presumably tuned against).
  • Rendering performance didn't seem to be much of an issue.
  • Very intensive HTML Webapps such as some in the Chrome experiment library did not start up as quick as in some other browsers.
  • WebGL is not supported so sites which fall back to software rendering of graphics from WebGL are much slower.

The biggest issue I had with WebView is that it is not quite as stable for cutting edge features and intensive use as other browsers, but not really any serious performance issues.

Here are a few benchmark stats (WebView version used was sourced from JavaFX 2.2 build 9):

Compliance

Running a html5 test to test html5 compliance (scores out of 500):

Chrome 19      402 + 13 bonus points
Firefox 12     345 +  9 bonus points
WebView 2.2b9  296 +  7 bonus points 
IE 9.0.6       138 +  5 bonus points

Running an acid3 test, webview scores 100/100 same as the other test browsers, but, like IE9, the final rendering has a slight imperfection.

Javascript

Sunspider Javascript benchmark (lower is better):

IE 9.0.6       146.7ms 
Chrome 19      151.5ms
Firefox 12     185.8ms
WebView 2.2b9  199.5ms 

Google V8 Javascript benchmark (higher is better):

Chrome 19      15323
Firefox 12     9557
WebView 2.2b9  5145
IE 9.0.6       3661

Mozilla Kraken Javascript benchmark (lower is better):

Chrome 19      2416.8ms
Firefox 12     2112.9ms
WebView 2.2b9  7988.9ms
IE 9.0.6       9403.0ms

Intensive Canvas

Spinning 3D buddha (higher is better):

Chrome 19      60fps
Firefox 12     43fps
IE 9.0.6       16fps
WebView 2.2b9  7fps

JQuery

JQuery test suite execution (lower is better):

Chrome 19      21826ms
WebView 2.2b9  22742ms
Firefox 12     23554ms
IE 9.0.6       28247ms

Based on the above benchmarks (run on my Windows 7 desktop), as long as WebView is stable and functional enough for you, then performance of WebView vs other browsers should not be an issue (as long as your app does not feature a lot of 3D spinning buddhas . . . :-).

Update

As uta's answer states, the JavaScript JIT compiler is switched on for the Win 32 bit build of JavaFX 2.2 and off for the Win 64 bit build of JavaFX 2.2. This means that WebView JavaScript benchmarks are significantly slower (typically 4 to 5 times slower) when running the 64 bit JavaFX version vs the 32 bit JavaFX version.

这篇关于JavaFX 中 WebView 的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆