Performance: scene-based background launch inflates _app_start until first foreground activation (12.19.2)

Open
#17,016 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
42/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
swift

Research direction

Start by tracing Firebase Performance's automatic app-start instrumentation and how it observes UIKit AppDelegate and SceneDelegate lifecycle events; the report names no source files or tests. Reproduce the background-before-first-activation sequence and compare the automatic _app_start duration with the lifecycle events. Done when background waiting time is excluded while normal foreground launches remain measured; the issue provides detailed reproduction steps but no public minimal project.

Written by the indexing model from the issue text.

Description

api: performance
Description

We observe minute-scale _app_start outliers in production, while our app-owned time-to-interactivity measurements remain much shorter.

During investigation, we reproduced a background-before-first-activation sequence locally. Firebase included the background waiting period in the automatic app-start trace.

Increasing the wait before foregrounding the application by 12 seconds increased the Firebase _app_start duration by approximately the same 12 seconds, while UI preparation time remained nearly unchanged.

This confirms the timing behavior in our local reproduction. We have not established that every production outlier has this cause.

Environment

  • Firebase Apple SDK: 12.19.2
  • Installation: Swift Package Manager
  • Product: Firebase Performance
  • Application lifecycle: UIKit AppDelegate + SceneDelegate, with UIApplicationSceneManifest
  • Reproduction device: iOS Simulator 27.2
  • Xcode: 27.2
  • Debug build, without an attached debugger or process suspension during the measured launches
  • Automatic instrumentation and performance data collection enabled locally

We used the application's existing test configuration to bypass Remote Config fetching and keep the performance configuration deterministic. Firebase SDK sources were not modified.

Expected behavior:
A genuine background launch should not include the wait until the user
first opens the application in the user-facing app-start duration.

At the same time, a normal foreground launch should not be discarded
simply because applicationState reports .background before scenes connect.

Related issues:
Possibly related to #10733 and the scene-based launch handling introduced
for #15802 / #15912.

We are not suggesting restoring the blanket .background check at
didFinishLaunching, since that would reintroduce the scene-based
foreground-launch problem.

Could you investigate this background-before-first-activation case?
Is there a supported workaround that excludes these measurements without
disabling network instrumentation, screen rendering, or app-owned custom
traces?

Reproducing the issue

This was reproduced in an existing UIKit application using AppDelegate
and SceneDelegate, with UIApplicationSceneManifest. I do not currently
have a public minimal reproduction project.

  1. Install and launch the application once in the iOS Simulator.
  2. Move the application to the background by opening Settings.
  3. Kill only the application's simulator process, without deleting
    application data, to model process eviction.
  4. Send a local simulated notification containing content-available: 1.
  5. Verify that:
    • the application process was absent before the notification attempt;
    • a new application PID exists afterward, before opening the app;
    • lifecycle logs show UI preparation while both the application and
      its scene are in the background;
    • UIApplicationDidBecomeActiveNotification has not occurred yet.
  6. Wait before foregrounding the application.
  7. Open the application and verify that the same PID is reused.
  8. Observe the first didBecomeActive event and Firebase's automatic
    app-start trace.
  9. Repeat with a longer wait before foregrounding.

No sleeps were inserted into application startup code. The controlled
delay was outside the application, between background launch and
foreground opening. No debugger or process suspension was used during
the measured launches.

Simulator notification limitation:

The content-available-only payload returned UNErrorDomain 1401
("Notification has no user visible content"). After adding alert
content, the command returned UNErrorDomain 2003 ("Repository could not
save notification. Source is not authorized").

Successful notification delivery or display is NOT claimed.
Nevertheless, the notification attempt spawned a new application
process in the background. We independently verified the new PID and
the application/scene lifecycle before foregrounding that same process.

Observed results:

Run 1. shorter wait before foregrounding:

  • Local UI preparation interval: 0.152 seconds.
  • didFinishLaunching entry to first didBecomeActive: 7.260 seconds.
  • Firebase automatic app-start trace: 7.321 seconds.

Run 2. longer wait before foregrounding:

  • Local UI preparation interval: 0.164 seconds.
  • didFinishLaunching entry to first didBecomeActive: 19.355 seconds.
  • Firebase automatic app-start trace: 19.399 seconds.

Increasing the controlled wait before opening the app by 12 seconds
increased Firebase's app-start duration by 12.078 seconds, while UI
preparation changed by only 12 milliseconds.

The UI preparation interval is a local diagnostic measurement, not a
claim that a custom Firebase trace was collected in the background.

Firebase SDK Version

12.19.2

Xcode Version

27.2

Installation Method

Swift Package Manager

Firebase Product(s)

Performance

Targeted Platforms

iOS

Relevant Log Output
Run 1:
12.19.2 - [FirebasePerformance][I-PRF100009] Logging trace metric - _as 7321.1930ms.

Run 2:
12.19.2 - [FirebasePerformance][I-PRF100009] Logging trace metric - _as 19399.2940ms.
If using Swift Package Manager, the project's Package.resolved

Relevant Firebase pin from Package.resolved:

{
"package": "Firebase",
"repositoryURL": "https://github.com/firebase/firebase-ios-sdk",
"state": {
"branch": null,
"revision": "8c29ca981990a32e626c8617544fa65d22b1834f",
"version": "12.19.2"
}
}

If using CocoaPods, the project's Podfile.lock
Expand Podfile.lock snippet

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

Dominant language
C++
Stars
7k
Forks
1.8k
Avg merge
1d 1h
Merged PRs (30d)
70

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from firebase/firebase-ios-sdk

All issues in firebase/firebase-ios-sdk

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.