firebase / firebase-unity-sdk

The Firebase SDK for Unity
http://firebase.google.com
Apache License 2.0
216 stars 35 forks source link

Editor freezes more than usual when hitting play. #378

Open axelbau24 opened 4 years ago

axelbau24 commented 4 years ago

Please fill in the following fields:

Unity editor version: 2019.3.7f1 Firebase Unity SDK version: 6.13.0 Source you installed the SDK (.unitypackage or Unity Package Manager): .unitypackage Firebase plugins in use (Auth, Database, etc.): FirebaseMessaging.unitypackage Additional SDKs you are using (Facebook, AdMob, etc.): None Platform you are using the Unity editor on (Mac, Windows, or Linux): Windows 10 Platform you are targeting (iOS, Android, and/or desktop): Android Scripting Runtime (Mono, and/or IL2CPP): Tried both

Please describe the issue here:

(Please list the full steps to reproduce the issue. Include device logs, Unity logs, and stack traces if available.)

Everytime i hit play (even on a empty project), Unity takes too long to build, compared to the usual time, this is not practical for me. Also, when the game starts (the play button becomes blue), the editor completely freezes for a few seconds as if it was compiling the game once again. Am i doing something wrong ?

To easily reproduce this issue:

This problem happens even if you don't have any base code running. Also, tried adding the google-services.json, but it doesn't do anything in this case.

Please answer the following, if applicable:

Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? Yes, the exact same thing happens here, and it feels worse.

What's the issue repro rate? (eg 100%, 1/5 etc) 100%

patm1987 commented 4 years ago

Hi @axelbau24 ,

Thanks for your report!

You've done everything right so far, but I've been unable to replicate the issue on my end. Can you tell me if you see any windows, dialogs, &c pop up after the first time you hit play (screenshot them if you like/can)? Do you see anything interesting in your Console window/would you mind sharing your Editor log? image

(note that if you don't feel comfortable sharing your Editor log publicly, you can file a bug here and link this issue/say you're trying to add information for this bug).

Is there anything else of interest that you can think of in your setup? Are you using meta files? A version control system other than Git? Is part of your unity project readonly or stored on a synced volume (ex: Dropbox, iCloud, &c)?

I'm checking in with the rest of the team to see if there's anything else we need to verify.

Thanks, --Patrick

almosr commented 4 years ago

I have similar experiences with Firebase Core and Analytics. If I remove them from the project then everything goes back to normal. I doubt that this would make any difference, but I used External Dependency Manager for Unity (EDM4U) and Unity Package Manager to install the packages.

Nothing is synced in the background for my project, it is a fairly straightforward setup. Code generation is set to .NET 4.x and IL2CPP, but changing the setting to Mono makes no difference.

A similar delay also happens when I switch from my code IDE (JetBrains Rider) to Unity editor, if there was any change on the source code and it is recompiled in the background Unity editor stops responding for a good 15-20 seconds.

I have tried profiling the editor to figure out what is going on. I am no expert on Unity profiling, but as it seems to me when this delay happens then profiler stops capturing anything until the editor starts working again.

Please let me know if there was any other information I could provide.

almosr commented 4 years ago

I have attached the editor log from the moment I press the play button: editor_log.txt

This line looks rather suspicious to me:

Unloading 534 unused Assets to reduce memory usage. Loaded Objects now: 5522.
Total: 15.606300 ms (FindLiveObjects: 0.836300 ms CreateObjectMapping: 0.170500 ms MarkObjects: 13.140400 ms  DeleteObjects: 1.457900 ms)

Edit: nevermind, I just realised it is msecs. :)

MateusMP commented 4 years ago

I might have the same issue. Looking at the editor profiler, there is at least one entry that seems suspicious to me: profiler

Note that I'm running on Windows 10. I can't say for sure if that XCodeProjectPatcher is related to firebase, but looking through some results on google it seems to be the case. But this seems to be a specific thing for IOS, so why is it running on my windows environment? It seems to be responsible for at least 4s of startup time.

I'm using Firebase 6.13, auth, database and analytics. And google admob. Running on SSD.

daksheshpatel commented 4 years ago

Exact same issue mentioned by MateusMP. It takes almost 4-5 seconds to enter play mode in the empty project with just Firebase core installed from package manager.

almosr commented 4 years ago

I am running Unity on Windows too, maybe this is an important piece of information.

axelbau24 commented 4 years ago

Thank you for your answer @patm1987

Here's my Editor Log Editor.log

Also, noticed some iOS stuff happening, even though i'm just compiling for Android, just like @MateusMP did, In my case i don't see anything related to XCode, just the iOS resolver (which i don't think it should be there and also taking a long time to compile.

profilerUnity

Is there any way to disable this iOS resolver?

EDIT: This was a completely empty project stored on my PC, no version control or cloud were used.

GorillaOne commented 4 years ago

I'm having a similar symptom (8 second slowdown right after entering playmode). Platform is set to Android. Same Unity and SDK version as original poster. I have also tried disabling all auto-resolve functions in the package, but this seems to get called no matter what. This is a critical issue.

image

Using Google Analytics for Firebase, Firebase Core, and Firebase Cloud Messaging.

leni8ec commented 4 years ago

I have the same issue. Freezes at 10-15 seconds on press play button.

Unity 2019.2.21, Firebase 6.12.0 and 6.13.0

GorillaOne commented 4 years ago

The majority of this slowdown appears to be due to the Google Play Resolver / External Dependency Manager. When removed, the slowdown goes away. Of course, Firebase won't load so you'll need to add it in again before you build - and this option only works when using the manual install because if you're using Firebase unity packages it will not let you uninstall the EDM because the firebase libraries rely on them.

godiemp commented 4 years ago

@GorillaOne How do I remove that? Thanks!

Hauki commented 4 years ago

I have the same issue. Freezes at 10-15 seconds on press play button.

kirilogan commented 4 years ago

I’m having the same issue, but on top of this the editor freezing for 20seconds after each code save. It’s getting unbearable. What would normally take me 2 mins to do, takes 3-4x as long.

I also tried a vanilla build using a brand new project and only adding firebase - same issue.

Anyone else experiencing delays between code changes and then switching over to the editor (even with out play)?

L4fter commented 4 years ago

I believe this is the same issue as in firebase/quickstart-unity#644

kirilogan commented 4 years ago

I believe this is the same issue as in firebase/quickstart-unity#644

I think you are right - I was looking at firebase/quickstart-unity#644 earlier and sounds very similar.

ideka commented 4 years ago

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it.

kirilogan commented 4 years ago

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it.

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it

What would be the downside of this? Would it be that you can’t add any new firebase packages or does the dependency manager get re-added (and that’s why we need to remove each time?)

ideka commented 4 years ago

What would be the downside of this? Would it be that you can’t add any new firebase packages or does the dependency manager get re-added (and that’s why we need to remove each time?)

You lose all firebase editor-specific functionality, but you can restore the folder when you actually need the functionality, and keep it removed when you don't. I assume you need it for building, resolving dependencies, probably for installing or removing packages too.

Obviously not ideal but I think it's a serviceable workaround for now, until this issue is fixed.

brunoschalch commented 4 years ago

Same issue here! When I play a scene, music starts to play but all graphics and the unity editor are frozen for a couple of seconds. I can confirm this happened only after adding Firebase Analytics (Android + iOS) to my project.

Unity 2019.3.10f1, Firebase 6.14.0

almosr commented 4 years ago

Deleting this folder: Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager does NOT solve the issue. It is a problem with Firebase and not EDM.

The only workaround I was able to figure out is to remove Firebase from the project while I edit it and put it back when I create a new build.

ideka commented 4 years ago

@almosr The workaround I posted definitely solves it for me. Maybe it's two different issues, or our environments are different somehow.

A reminder just in case, Unity restores the folder when you open the project, so you have to delete it when the project is already open.

almosr commented 4 years ago

@ideka When I deleted that aforementioned folder while Unity is open then the issue disappears, because Firebase fails to initialize. Unity keeps throwing various errors, I would rather recommend to remove Firebase from the dependencies, that is a cleaner way to workaround the issue.

kirilogan commented 4 years ago

@ideka Thanks! I can confirm that this works for me (and yes, it shows the Editor error), but everything else seems to work fine (fireauth, firestore, cloud functions). I can live with this hack for now :D

@almosr I could, but I'm already fairly far along with firebase

GorillaOne commented 4 years ago

@almosr Removing EDM while working in the project works for me as well. As mentioned above, Unity regenerates the EDM when you open the project and when you open the Package Manager.

If you don't need firebase, then removing firebase is an excellent option. However, I'm assuming that the folks here, like myself, who have this problem need firebase. Removing the EDM when you open the application prevents the slowdown because it prevents the Firebase editor scripts from running, which is where I believe the issue is located. It's not great, but its just a workaround until they fix it.

ewjordan commented 4 years ago

Not sure if it's already been made explicit or not, but I've been working on the same project in the Windows 10, OS X, and Linux versions of Unity, several different versions, and this only seems to happen on Windows (all 2019 versions I've tried), so you'll have trouble reproing on GLinux or Mac.

My workaround is to locally delete Firebase.Editor.dll and its meta file, and the issue goes away (but I don't commit or it breaks our game in CI builds), but if that dll is anywhere in even an otherwise empty project, things get slow. This has been happening since at least January, and in particular before the migration to the Unity package manager install, so it's not a particularly new change that's caused it.

MWFIAE commented 4 years ago

For me it's also crippling slow with Unity 2019 and Windows10. However it seems like deleting the editor.dll doesn't bring any noteworthy improvement. Startup times are around 20 seconds and also freezes if I change anything in vs code and come back to unity.

Basically impossible to work like this.

igor84 commented 4 years ago

Seems firebase/quickstart-unity#667 is duplicate of this one. The problem seems very straight forward:

  1. GenerateXmlFromGoogleServicesJson class has a [InitializeOnLoad] attribute so Unity will load it and execute its static constructor after each recompile and when entering play mode.
  2. Static constructor will schedule CheckConfiguration() to be called on first next Update,
  3. which will then call UpdateConfigFileDirectory()
  4. which will for every "google-services.json" and "GoogleService-Info.plist" file in project call ReadBundleIds(file)
  5. which will run "generate_xml_from_google_services_json.exe" on Windows and "python generate_xml_from_google_services_json.py" on other platforms and each invocation of that takes more than 5 seconds, keeping the Editor frozen.

Surely Firebase doesn't need to do all this on each load so please just cache it somehow or something so we can continue making games :)

aleksandrdolbilov commented 4 years ago

You can speedup recompile time by removing 'generate_xml_from_google_services_json.py'. After that you will see error message on each recompile. But that's ok. Also you have to restore this file before 'platform build'.

miv commented 4 years ago

You can speedup recompile time by removing 'generate_xml_from_google_services_json.py'.

I've tried that but Unity will restore it pretty quickly in my case.

aleksandrdolbilov commented 4 years ago

I think it restores 'generate_xml_from_google_services_json.py' on Unity restart. Can be solved with simple Unity script which only responsibility is to delete it.

L4fter commented 4 years ago

I'll copypaste my comment from another closed thread on this topic. I strongly believe that optimizing the performance/caching/removing files when not building are just half measures. The real question is should this code run all the time at all? I think the best solution is to make an option of not running this code at all. In the end, when no plugins have been changed, it does nothing and takes 10-20 seconds. So my suggestion is to make two options, like:

I don't mean that there should be no optimization, only that providing these options imo is faster and more reliable way to deal with the issue.

aleksandrdolbilov commented 4 years ago

That's 100% true, we need solution from Google, but also we have to make games now) That's a dirty hack to save some time and continue to use Firebase.

igor84 commented 4 years ago

Note in the stack trace that I described that this is done from a method called CheckConfiguration. Its purpose seems to be checking how your project is configured and if it finds something off it presents a dialog to the user telling him about it and offering him a way to fix it. That is probably a reason it can't just run on build since if build is running within some auto build system, there is no user that can be asked to fix the issue.

Still there must be a way to optimize it or have it run only in some special circumstances and not always.

NoobsArePeople2 commented 4 years ago

I'm experiencing this issue in Unity 2019 on Windows 10 as well. Unity is effectively impossible to use with Firebase in this state.

I've not been able to find any of the files in the posted workarounds so this issue is a hard blocker for me. Getting a fix for this issue prioritized would be great as Firebase is otherwise quite nice and I'd like to continue using it.

jimanjr commented 4 years ago

Happening here as well. Workarounds posted above did nothing here. Have an Android project on Windows 10, yet the callstack shows me an Xcode project check.

  1. Should probably not run Xcode project checks on windows/android.
  2. Probably should not automatically run these checks on every build. Maybe a Debug.LogError for issues with the project.
  3. Maybe make this a build step instead of a "play" step? Maybe some defines or options to disable this when we're testing gameplay stuff that has nothing to do with Firebase.

Running the game takes 13 seconds on the python script alone (on a fast SSD and a 3950X).

ewjordan commented 4 years ago

Not sure if it's already been made explicit or not, but I've been working on the same project in the Windows 10, OS X, and Linux versions of Unity, several different versions, and this only seems to happen on Windows (all 2019 versions I've tried), so you'll have trouble reproing on GLinux or Mac.

My workaround is to locally delete Firebase.Editor.dll and its meta file, and the issue goes away (but I don't commit or it breaks our game in CI builds), but if that dll is anywhere in even an otherwise empty project, things get slow. This has been happening since at least January, and in particular before the migration to the Unity package manager install, so it's not a particularly new change that's caused it.

It's worth noting that after we updated to the newer package manager install, this doesn't work anymore.

wwalton86 commented 4 years ago

The issue is still present in 6.14.0, EDM version 1.2.153.

As a workaround for those using the Package Manager versions, you can simply delete the Editor folder and Editor.meta file within Library/PackageCache/com.google.external-dependency-manager@1.2.153/ExternalDependencyManager. You may have to do it every time you start Unity.

You'll sometimes get an error message about failing to load Firebase.Editor.dll, but it seems you can safely ignore it.

This has been working for me. Quick and easy until it's fixed.

Whyser commented 4 years ago

This has actually been an issue for a long time (freeze upon hitting Play caused by some part of Firebase), but this latest version (not sure which I had before) is about 2x as slow as it was before which is unbearable. Please fix this asap with a manual toggle for now. :/

mikeypdev commented 4 years ago

Same freeze issue on macOS, Unity 2019.3.5f1, SDK 6.14 installed from UPM (migrated from earlier .unitypackage installs). In my case, the issue is caused by EDM, not directly by the python generator script (though see @igor84 note in issue firebase/quickstart-unity#667). The workaround with deleting the EDM Editor folder works, along with the noted side-effects.

I found a more reliable workaround using the new "Enter Play Mode Settings" option introduced in Unity 2019.3. https://blogs.unity3d.com/2019/11/05/enter-play-mode-faster-in-unity-2019-3/

In the Edit menu, Player Settings, Editor section, I enabled "Enter Play Mode Options (Experimental)". For my project, I disabled the "Reload Domain" option, and enabled the "Reload Scene" option.

Screenshot_5_16_20__2_13_PM

Play mode starts within a second or so for me now. Note that this feature could introduce other bugs, depending on your project. I seem to have good luck so far.

Whyser commented 4 years ago

Thanks for the other workaround Mike! I actually tried that about a month ago and it is indeed quick! But because of some static refs throughout the project it's very troublesome to manage on our end. So a caution for people trying it out, read Unitys warning about it before you start relying on it. :)

summitsteven commented 4 years ago

We are also having a really hard time with this behavior. We've tried going over to a manual install to avoid the Dependency Manager entirely, but that has caused difficulties in the build process.

This is extremely frustrating to work with as it will freeze for 30 seconds every time

This crushes developer productivity.

I've written a small script that will execute @ideka 's workaround automatically - deleting the Dependency Manager editor scripts. The initial load of Unity is still slow, but after that the script runs and recompiles/playing should be back to "normal".

Looking forward to a proper resolution!

#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEditor;
using UnityEngine;

[InitializeOnLoad]
public class SuppressDependencyManager 
{
    static SuppressDependencyManager()
    {
        Debug.Log("Deleting dependency manager files in attempt to work around https://github.com/firebase/firebase-unity-sdk/issues/378");

        var editorFolderPath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Library", "PackageCache", "com.google.external-dependency-manager@1.2.153", "ExternalDependencyManager", "Editor");
        var editorMetaPath = Path.Combine(System.IO.Directory.GetCurrentDirectory(), "Library", "PackageCache", "com.google.external-dependency-manager@1.2.153", "ExternalDependencyManager", "Editor.meta");
        if (Directory.Exists(editorFolderPath))
        {
            Directory.Delete(editorFolderPath, true);
        }
        if (File.Exists(editorMetaPath))
        {
            File.Delete(editorMetaPath);
        }
    }
}
#endif
bhallionOhbibi commented 4 years ago

I was able to patch the Firebase.Editor.dll using dnSpy to avoid the freeze each time you press play. Everything seems to works and the freeze is gone !

I did the following:

You should now have a patched version of Firebase.Editor.dll which doesn't call the python script each time you press Play.

This is only a workaround and it fix only the issue when pressing PLAY. The freeze still occurs after each compilation. But once you start modifiying code, you can do pretty much anything. So I guess you could add an EditorPrefs per exemple to enable/disable the problematic method.

You can find a patched version I made for firebase 6.13.0 here: https://github.com/bhallionOhbibi/FirebaseEditorDll

Whyser commented 4 years ago

I'm gonna ping @DellaBitta (sorry, if you're the wrong person!) but maybe you can move/merge/assign this issue so we dont have to download a potentially malicious DLL to fix this issue (no offense bhallionOhbibi, really appreciate your effort!)?

DellaBitta commented 4 years ago

Hi @Whyser,

I'll send it to the team for review. Thanks!

RadekMikulkaAG commented 4 years ago

are there any news about this issue? It is there for soo long :(

igor84 commented 4 years ago

The best workaround I came up with is to use dnSpy to change and recompile Firebase.Editor.dll as @bhallionOhbibi described but I changed it a bit differently. I removed the call to GenerateXmlFromGoogleServicesJson.CheckConfiguration() from static constructor but I made that method public and added [MenuItem("Windows/Firebase/Check Configuration")] above it. Then in my project I call it from my implementation of IPreprocessBuildWithReport.OnPreprocessBuild described here: https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.html

That way it is automatically called before the build and I can also manually call it anytime from the menu, but it is not invoked on each recompile and when entering play mode.

DellaBitta commented 4 years ago

Hi all, a status update: the proposed change from @bhallionOhbibi will be part of our official 6.15.0 release -- currently in progress.

Whyser commented 4 years ago

Della please don't let it do this process during compilation of scripts. I would say Igor's solution is better to only do during build (or manually).

chkuang-g commented 4 years ago

@Whyser Your suggestion make sense. That process creates two files out of google-services.json/GoogleServices.plist

  1. google-services.xml for Android build
  2. google-services-desktop.json for the editor

We might be able to postpone 1 until build time. It will take some time to refactor and we need to investigate the right timing to generate it for different Android build configuration.

There are more improvement can be done for the freeze. As for next release, we only integrated @bhallionOhbibi suggestion for temporary relief. More improvement will be coming from either Firebase or EDM4U.

Thanks for the update!

mikeypdev commented 4 years ago

Still seeing the play mode delay in 6.15.0 on macOS. Anyone else, or am I possibly seeing another issue?