gree / unity-webview

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Poor/slow performances

Durss opened this issue · comments

Hello !

Before anything, thank you for your work and for sharing it !

Now, my problem.
I just tried this plugin on android and i get very very poor performances.
I first tried on my Vurforia project (making sure vuforia is disabled while webview is displayed) and the performances of my page are literally desastrous on a Pixel C (~2-6 fps when scrolling a scrollable div with very few animations and images on it) on OnePlus 6T it's ok but still slower than on the brower.
The page works perfectly fine on chrome on the same devices.
I tried the sample project, same problem.

I just realized that when splitting the screen to display two apps at the same time, the webview being smaller it runs way more smoothly. (probably due to some rasterization stuff?)

Is there anything i'm missing ? Hardware acceleration is properly enabled on the android manifest.

Thank you :)

As Pixel C supports Vulkan, your app may run on Vulkan if you don't tweak any setting for Android. Vulkan is still new and not optimized well for the whole system, a WebView view might be interfered with Vulkan. Could you please try to disable Auto Graphics API and enable only OpenGLES2/OpenGLES3 as below:

image

Thank you for your answer !
I tried that with no much success though :/

It's not critical for my demo project so for now i just redirect from the webpage to the native app via an URL schema.
I also tried making a native android app with a native webview and it works fine.

I further investigated and finally found a Unity 2018-specific issue: https://stackoverflow.com/questions/12429792/how-to-dynamically-change-attribute-of-an-xml-node-with-c-sharp . I've fixed the post-process for Unity 2018 in #344 and confirmed a resulting apk contains androind:hardwareAccelerated="true".

Thank you very much for your report! Could you please try the latest?

Awesome !!

It took me some time to figure out i had to use gradle builder instead of internal to get postprocessor executing (so it had no chance to work before that anyways... ahem)
It might be worth mentionning this in the readme :)

If i inspect the AndroidManifest.xml inside the generated APK the "hardwareAccelerated" property is set to false on the node which seems weird to me but performances are good anyways. Is it normal ?
I put some logs on the postProcessor to make sure it was executed properly and it seems to be.

PS: thank you for your reactivity !!

Oh ! I forgot to mention, i think you forgot to add the new postProcessor to the UnityPackage and the Zip. I had to get it from there and add it to my project manually :
https://github.com/gree/unity-webview/blob/master/plugins/Android/Editor/UnityWebViewPostprocessBuild2018_1.cs

Thanks again! I've fixed to include UnityWebViewPostprocessBuild2018_1.cs and updated binaries.
cf. #345

If i inspect the AndroidManifest.xml inside the generated APK the "hardwareAccelerated" property is set to false on the node which seems weird to me but performances are good anyways. Is it normal ?

Hmm, it should be set to true, maybe there might be confusion as I missed the new post-process script to be included. The following is a screen shot of Analyze APK... of Android Studio for the sample app generated with the latest.
image

I tried importing the package again via the "unity-webview.unitypackage" file but the new postProcess build file seems to still be missing from it. Same for the zip file (inside the dist dir).
image

That's strange about the hardwareAccelerated flag, just double checked after importing the postprocess build file (2018_1) again but it's still set to false :
image

Is there any other configuration somewhere i could have missed? Likle the build system that should be set to "Gradle" for example.

UnityWebViewPostprocessBuild.cs in the package is built with three source plugins/**/Editor/UnityWebViewPostProcessBuild*.cs. Could you please open it and check whether it contains the content of UnityWebViewPostprocessBuild2018_1.cs?
cf.

sh "cat #{DSTDIR[0]}/Android/Editor/*.cs #{DSTDIR[0]}/iOS/Editor/*.cs > #{DSTDIR[0]}/Editor/UnityWebViewPostprocessBuild.cs"

About the hardwareAccelerated flag, could you please try to build the sample app (if you currently try to build your app)?

Ah, also in the past, I've experienced UNITY_ANDROID and/or UNITY_IOS were occasionally not set in the post build script. Could you please also try to replace UNITY_ANDROID and UNITY_2018_1_OR_NEWER with true as below?

--- UnityWebViewPostprocessBuild.cs.orig	2018-08-23 09:51:39.000000000 +0900
+++ UnityWebViewPostprocessBuild.cs	2018-08-23 19:39:27.000000000 +0900
@@ -1,5 +1,5 @@
-#if UNITY_ANDROID
-#if !UNITY_2018_1_OR_NEWER
+#if true
+#if !true
 using System.Collections;
 using System.IO;
 using System.Xml;
@@ -85,8 +85,8 @@
 }
 #endif
 #endif
-#if UNITY_ANDROID
-#if UNITY_2018_1_OR_NEWER
+#if true
+#if true
 // cf. https://forum.unity.com/threads/android-hardwareaccelerated-is-forced-false-in-all-activities.532786/
 // cf. https://github.com/Over17/UnityAndroidManifestCallback
 using System.IO;

Okay, now I introduced a new unified UnityWebviewPostprocessBuild.cs that has no dependency for UNITY_ANDROID/UNITY_IOS flags, and updated binaries. This one should not have the issue described above.
cf. #346

Just tried and it seems all good thank you :D !
I just had to comment out the iOs parts because i'm on windows and haven't installed iOs build support. But the flag is set to true properly now !

Thank you very much for your support 🥇

Thank you for the detailed note!