firebase-ios-sdk icon indicating copy to clipboard operation
firebase-ios-sdk copied to clipboard

FirebaseApp.configure() triggers "Slow launches" warning on Xcode 16 / iOS 18

Open alex-vasenin opened this issue 1 year ago • 21 comments

Description

I just switched to Xcode 16 and iOS 18 and running my app on the device started producing following runtime warnings on every app start:

/Pods/FirebaseCrashlytics/Crashlytics/Crashlytics/FIRCLSUserDefaults/FIRCLSUserDefaults.m:288 Performing I/O on the main thread can cause slow launches. This is known to cause slow launches for your users.

/Users/alexvasenin/Documents/MeteorActive/Pods.nosync/FirebaseCore/FirebaseCore/Sources/FIRApp.m:348 Performing I/O on the main thread can cause slow launches. This is known to cause slow launches for your users.

The first warning appears one time while the second one is repeated 6 times. All of the stack traces go through [FIRApp configure]. I did a quick test and indeed I found a call to FirebaseApp.configure() takes about 400-600ms on iPhone 15. However, I found if the debugger is NOT attached, the call takes only ~30ms, so it looks like the multiple stack unwinding takes the most time.

Having 7 runtime warnings without a good reason is bad. Please help to solve or silence this warnings.

Reproducing the issue

No response

Firebase SDK Version

10.2.0

Xcode Version

16.0

Installation Method

CocoaPods

Firebase Product(s)

Analytics, Crashlytics, Performance

Targeted Platforms

iOS

Relevant Log Output

No response

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet

Replace this line with the contents of your Package.resolved.

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet

Replace this line with the contents of your Podfile.lock!

alex-vasenin avatar Sep 19 '24 18:09 alex-vasenin

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

google-oss-bot avatar Sep 19 '24 18:09 google-oss-bot

Screenshot 2024-09-19 at 13 29 54

alex-vasenin avatar Sep 19 '24 18:09 alex-vasenin

Do you see the same thing with more recent releases? 11.2.0 is the latest release.

paulb777 avatar Sep 19 '24 19:09 paulb777

My bad, I do actually use the latest release 11.2.0

alex-vasenin avatar Sep 19 '24 20:09 alex-vasenin

image I also face the same issue. I use the release 11.1.0

chenyanping01 avatar Sep 26 '24 09:09 chenyanping01

I'm not able to reproduce, but it seems to be related to Analytics and Crashlytics doing I/O on the main thread during initialization. @htcgh @themiswang would you take a look?

paulb777 avatar Sep 30 '24 22:09 paulb777

we are encountering this as well. Same issue as above.

oglerma avatar Oct 10 '24 20:10 oglerma

I'm using Firebase 11.4.0 and encountering this. @paulb777 @htcgh have you been able to explore this? What additional information would be useful towards helping investigate and resolve this? Thank you.

hsoi avatar Oct 25 '24 17:10 hsoi

The best help would be a fully reproducible example.

paulb777 avatar Oct 25 '24 18:10 paulb777

To take @chenyanping01 's screenshot a bit further, I opened one of our logs in Xcode (note: this is coming via Apple's analytics via Xcode Organizer; so this is production version of our app -- no debugger involved).

image

So yes, people are calling FirebaseApp.configure() at their app launch (on the main thread), and eventually it winds up blocking to wait for a dispatch group (on the main thread).

I found the highlighted comment in there interesting: "…we also want to wait as long as possible for these to be complete. If we do not, there's a chance that we will not be able to correctly report a crash shortly after start." That certainly seems… conflicting. 🤔

I doubt I could create an isolated simple repro (if you're unable to reproduce it yourself) -- sounds like you'd need our project. I'd have to talk with the boss-man about lobbing the whole project to y'all. If it winds up being doable, @paulb777 how would we work this (to get it to you, etc.)? Thanks.

hsoi avatar Oct 25 '24 18:10 hsoi

Thanks. To be clearer, we have a reasonable understanding of the Crashlytics problem, but not yet a solution.

The Analytics/Installations/Performance hangs are less clear and that is where we'd like to find more data since we haven't been able to reproduce

paulb777 avatar Oct 25 '24 20:10 paulb777

@paulb777 appreciate the clarity. I chatted with the boss-man and sending the whole codebase is a no-go (not unexpected). Still, is there any way I could assist? Instrument something? generate some logs? I mean, it's basically "debugging by carrier pigeon" here 😆, but hey, if there's something I can do to help to move the needle, I'm game.

hsoi avatar Oct 25 '24 20:10 hsoi

Yes we also face same issue in our application ? When there will be solution

SuryakantRapido avatar Nov 05 '24 10:11 SuryakantRapido

I was investigating a similar issue on the Android-SDK and confirmed that Crashlytics and Analytics performing i/o disk read operations on main thread was intended behaviour and I do not think it would be outlandish to assume the same here. It may not be something to worry about unless its significantly increasing app startup time or compromises functionality.

MichaelVerdon avatar Nov 21 '24 14:11 MichaelVerdon

@MichaelVerdon Thanks for investigating. Our SDKs should not cause warnings for app developers and we should develop plans to stop doing I/O on the main thread.

paulb777 avatar Nov 21 '24 19:11 paulb777

@paulb777 Any update are we doing something on this ?

SuryakantRapido avatar Nov 22 '24 09:11 SuryakantRapido

We're seeing these warnings too, from [FIRapp configureCore]:

Bildschirmfoto 2024-11-29 um 10 26 51

Xcode 16.1, Firebase SDK 11.4.0 added via SPM

gereons avatar Nov 29 '24 09:11 gereons

Same here but in remote config: Xcode 16.1, Firebase SDK 11.5.0 added with CocoaPods Screenshot 2024-12-07 at 10 38 17

xavipedrals avatar Dec 07 '24 09:12 xavipedrals

We also face same issue, currently using release 11.6.0 Xcode organizer shows 380 ms spent in this code path during launch.

Image

salmaanahmed avatar Jan 20 '25 03:01 salmaanahmed

Just to add to this we have an app with 5M+ users and this now contributes to 30% of our slow launches. Would be great to have an update on the issue. Image

cnordvik avatar Jan 22 '25 07:01 cnordvik

Same here, but somehow shows the error when setting deepLinkURLScheme.

Image

akbashev avatar Feb 07 '25 08:02 akbashev

Any update planned on this ?

Edit: After More testing by removing sides effect from my projects I found that:

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
    }
}

does not reproduce the issue but having a single Analytics.logEvent calls anywhere in the codebase produce it

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        Analytics.logEvent("TEST", parameters: [:])
    }
}

the only working solution I see if we want to call configure from app-delegate asap would be to use a Task

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    func application(_ application: UIApplication,
                     didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Task(priority: .high) { @MainActor in
            FirebaseApp.configure()
            Analytics.logEvent("TEST", parameters: [:])
        }
    }
}

The requirement becomes to prevent any calls to Firebase and friends before this is called, you could make a dirty actor for that or something.

lifely avatar Mar 07 '25 19:03 lifely

This issue now contributes to 40% of our slow launches. Version: Firebase/Crashlytics (11.9.0) Would be great to have an update on the issue.

Image Image

alflix avatar Mar 21 '25 05:03 alflix

Hi all. I can't speak for Crashlytics, but I increased the relative priority of the Analytics dispatch queues in Firebase 11.11.0, which was released earlier today. Please let us know if it helps resolve the "slow launches" warnings.

htcgh avatar Apr 01 '25 00:04 htcgh

Hi all. I can't speak for Crashlytics, but I increased the relative priority of the Analytics dispatch queues in Firebase 11.11.0, which was released earlier today. Please let us know if it helps resolve the "slow launches" warnings.

It does not help in Firebase 11.11.0

alflix avatar Apr 14 '25 02:04 alflix

@themiswang Can you take a look on the Crashlytics side?

htcgh avatar Apr 14 '25 18:04 htcgh

Hey folks, for Crashlytics we are working on improving the startup time. We'll let you know when a fix is ready.

samedson avatar Apr 23 '25 13:04 samedson

Hey folks, we just made a change that should improve the startup time of Crashlytics. It'll be included in the next Firebase SDK release.

If you'd like to test it out early it's on this PR: https://github.com/firebase/firebase-ios-sdk/pull/14754.

samedson avatar May 01 '25 15:05 samedson

We are also facing this issue in 11.12.0. can you please update us when it will be fixed?

Image

hr147 avatar May 02 '25 06:05 hr147

Thanks everyone for your patience. A fix has been merged and will release as part of 11.13.0 which is planned for the week of May 15th.

ncooke3 avatar May 07 '25 13:05 ncooke3