Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poor/slow performances #342

Closed
Durss opened this issue Aug 20, 2018 · 12 comments
Closed

Poor/slow performances #342

Durss opened this issue Aug 20, 2018 · 12 comments

Comments

@Durss
Copy link

Durss commented Aug 20, 2018

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 :)

@KojiNakamaru
Copy link
Member

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

@Durss
Copy link
Author

Durss commented Aug 22, 2018

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.

@KojiNakamaru
Copy link
Member

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?

@Durss
Copy link
Author

Durss commented Aug 22, 2018

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

@Durss
Copy link
Author

Durss commented Aug 22, 2018

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

KojiNakamaru added a commit that referenced this issue Aug 23, 2018
@KojiNakamaru
Copy link
Member

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

@Durss
Copy link
Author

Durss commented Aug 23, 2018

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.

@KojiNakamaru
Copy link
Member

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)?

@KojiNakamaru
Copy link
Member

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;

@KojiNakamaru
Copy link
Member

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

@Durss
Copy link
Author

Durss commented Aug 23, 2018

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 🥇

@KojiNakamaru
Copy link
Member

Thank you for the detailed note!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants