Crashlytics setup in Firebase - Time & Space Complexity
When setting up Crashlytics in Firebase, it's important to understand how the time to complete setup grows as you add more features or apps.
We want to know how the number of setup steps or API calls changes as the project grows.
Analyze the time complexity of initializing Crashlytics for multiple apps.
// Assume `apps` is an array of initialized Firebase app instances
const crashlyticsInstances = apps.map(app => getCrashlytics(app));
// Log a test error for each Crashlytics instance
crashlyticsInstances.forEach(crashlytics => {
crashlytics.log('Test error');
});
This sequence sets up Crashlytics for multiple Firebase apps and logs a test error for each.
Look at what repeats as the number of apps grows.
- Primary operation: Initializing Crashlytics instance for each app.
- How many times: Once per app in the list.
- Secondary operation: Logging a test error for each Crashlytics instance.
- How many times: Once per Crashlytics instance.
As the number of apps increases, the number of Crashlytics initializations and log calls grows the same way.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 initializations and 10 log calls |
| 100 | About 100 initializations and 100 log calls |
| 1000 | About 1000 initializations and 1000 log calls |
Pattern observation: The number of operations grows directly with the number of apps.
Time Complexity: O(n)
This means the setup time grows in a straight line as you add more apps to initialize Crashlytics for.
[X] Wrong: "Initializing Crashlytics once is enough for all apps."
[OK] Correct: Each app needs its own Crashlytics setup, so the work grows with the number of apps.
Understanding how setup steps grow with project size shows you can plan for scaling and manage resources well.
"What if we batch log errors instead of logging one by one? How would the time complexity change?"