Unity editor version: 2019.2.21
Firebase Unity SDK version: 6.14.0
Source you installed the SDK: Unity Package Manager
Firebase plugins in use: Auth, Analytics, Crashlytics, Database, Messenger:
Additional SDKs you are using: not relevant
Platform you are using the Unity editor on: Mac and Windows
Platform you are targeting: iOS and Android
Scripting Runtime: IL2CPP and Mono
I notice that on every frame Firebase is allocating garbage.
It's not much but I wonder if it can be avoided.
The garbage collection 144B every frame, seems to be split in two parts one 112B and other 32B
The allocation seems to come from FirebaseHandler.cs and when decompiling Firebase.Platform.DLL I can see the cause of this.
FirebaseMonoBehaviour is calling FirebaseHandler.Update if it exists.
In FirebaseHandler.Update there is this code (decompiled with dotPeek)
internal void Update()
{
FirebaseHandler.ThreadDispatcher.PollJobs();
FirebaseHandler.AppUtils.PollCallbacks();
if (this.Updated != null)
ExceptionAggregator.Wrap((Action) (() => this.Updated((object) this, (EventArgs) null)));
ExceptionAggregator.ThrowAndClearPendingExceptions();
++FirebaseHandler.tickCount;
}
Notice the section:
(Action) (() => this.Updated((object) this, (EventArgs) null))
This is creating garbage every single frame.
Can't the Action be created when this.Updated delegate is set and then reused ?
It seems to be it's always the same, as long as this.Updated does not change and since there is easy to keep track of that it should just as easily be possible to create Action and reuse it rather than to recreate same Action every single frame.
What's the issue repro rate?: 100%
This issue does not seem to follow the issue template. Make sure you provide all the required information.
@snorrsi
That's a valid point. We'll see what we can do here.
The same happens for us:
Unity 2019.3.12f1.
Firebase 6.14.1.
Unity Package Manager.
Auth, Analytics, Crashlytics, Firestore, Storage
Mac and Windows
iOS and Android
IL2CPP
Profiled on Android. Every frame FirebaseHandler.Update() allocates 144 B. 112 B are allocated in FirebaseHandler.Update(), the other 32 B are allocated in FirebaseAuthService.RefreshExpiredTokens()
It is very important that the plugin does not produce any garbage every frame.
I wonder nobody cares about performance. The every frame allocation produces a lot of garbage. Which results to many garbage collections. Guys, this plugin is for mobile platform!
What is the status of this issue?
@khindemit it sadly seems that they don麓t take this issue seriously as it麓s listed as instead feauture request instead of bug which it surely is. It furthermore should be easily fixable.
Maybe @chkuang-g can give some status update and explain why this is not listed as a bug?
@snorrsi
I'm currently looking into several performance improvement for Unity SDK and will include some change to reduce GC every frame in the next release.
We made the changes to remove Action allocation in each frame and FirebaseAuthService.RefreshExpiredTokens and they will be included in the next release
Can it be disabled in the mean time, e.g. in a scene where it's guaranteed to not be unloaded?
Unfortunately there is no easy way to disable this unless you edit the assembly Firebase.Editor.dll directly.
If you like to do that, what you need to do is to find FirebaseHandler and change Update() to the following:
internal void Update()
{
FirebaseHandler.ThreadDispatcher.PollJobs();
FirebaseHandler.AppUtils.PollCallbacks();
ExceptionAggregator.ThrowAndClearPendingExceptions();
++FirebaseHandler.tickCount;
}
Basically remove the entire part that is causing GC. Last time when I checked, it is only used for some deprecated features, which I've removed for the next release already.
Hi folks,
Good news! 6.16.0 was release and we removed all those legacy codes to improve GC in each frame.
I'll close this issue for now. If the issue remains, please report a new bug using bug template
Most helpful comment
We made the changes to remove Action allocation in each frame and
FirebaseAuthService.RefreshExpiredTokensand they will be included in the next release