Custom events in Firebase - Time & Space Complexity
When using Firebase custom events, it's important to know how the number of events affects performance.
We want to understand how the time to send events grows as we send more events.
Analyze the time complexity of sending multiple custom events to Firebase Analytics.
for (let i = 0; i < n; i++) {
firebase.analytics().logEvent('custom_event', { event_number: i });
}
This code sends n custom events, each with a unique number, to Firebase Analytics.
We look at what repeats when sending events.
- Primary operation: Calling
logEventto send one event to Firebase. - How many times: Exactly
ntimes, once per event.
Each event requires one call to send it. So, if you double the number of events, you double the calls.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 calls |
| 100 | 100 calls |
| 1000 | 1000 calls |
Pattern observation: The number of calls grows directly with the number of events sent.
Time Complexity: O(n)
This means the time to send events grows in a straight line with the number of events.
[X] Wrong: "Sending many events at once only takes the same time as sending one event."
[OK] Correct: Each event requires its own call, so more events mean more time.
Understanding how event sending scales helps you design efficient analytics and avoid slowdowns in apps.
"What if we batch multiple events into one call? How would the time complexity change?"