Cordova/Phonegap slow performance with Open Layers

2019-08-06 09:17发布

问题:

I have developed an application which uses Cordova/Phonegap on Android to display Open Layers 3 maps.

It is quite similar to this project:

https://github.com/netgis/ol3

I have found that the application runs smoothly on the Samsung Note 4 running Kitkat V4.4.4, and runs fine on an old S2 running Jellybean (almost equally well in fact), but it runs terribly slowly on a bran new Galaxy Tab Pro 12.2 running KitKat V4.4.2.

I was wondering if there is any Cordova/Phonegap expert out there who might know why.

The only difference between them that I can see is the version of android! V4.4.4 and V4.4.2.

I have discovered threads on SO which generically say that WebView can be a problem and cause slow performance, but I'm getting great performance on my Note 4, and the S2 runs better than the tablet does using Jellybean.

I'm not sure code would be useful to show here, essentially I have a Cordova Android application with a single HTML document with Open Layers 3 map embedded, that's it.

回答1:

The problem turns out to lie with WebView, which uses the default Android browser. For some reason this browser restricts CPU support if you're trying to use GPU acceleration (enabled by default), but doesn't provide GPU acceleration itself (it's really strange but true).

Apparently KitKat has this problem prior to Android V4.4.3. So if you're running V4.4.4 you won't encounter this performance problem as it has been fixed (as it uses Chromium instead of the default browser).

Here's one of many references I've found which corroborate this:

https://code.google.com/p/chromium/issues/detail?id=315111

Some devices haven't yet been updated to this level, here are my completely up to date devices:

The tablet uses Android V4.4.2

The S2 uses Android V4.0.2

The Note 4 uses Android V4.4.4

The S2 uses Jelly Bean and is therefore fine, the Note 4 uses the updated KitKat and also runs fine, but the tablet struggles with the application to such an extent it is unusable owing to it being below V4.4.3.

For me, the majority of suggested solutions on SO are to disable hardware acceleration, but these suggestions are unsuitable as my application really does require hardware acceleration to render maps efficiently.

The solution is to take this problem away completely by forcing the use of Chromium irrespective of the OS Version through the use of Crosswalk.

There are plenty of resources I've found to use Cordova in synergy with crosswalk:

https://crosswalk-project.org/documentation/cordova.html

https://blog.nraboy.com/2014/10/use-crosswalk-ionic-framework-android-apps/