Bundle preloading in Firebase - Time & Space Complexity
We want to understand how the time to preload bundles grows as we add more bundles to preload in Firebase hosting.
Specifically, how does the number of bundles affect the number of preload operations?
Analyze the time complexity of the following operation sequence.
const bundles = ["bundle1.js", "bundle2.js", "bundle3.js"];
bundles.forEach(bundle => {
firebase.hosting.preloadBundle(bundle);
});
This code preloads each JavaScript bundle one by one using Firebase Hosting's preload API.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Calling
firebase.hosting.preloadBundle()for each bundle. - How many times: Once per bundle in the list.
Each additional bundle adds one more preload call, so the total calls grow directly with the number of bundles.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 preload calls |
| 100 | 100 preload calls |
| 1000 | 1000 preload calls |
Pattern observation: The number of preload operations grows linearly as the number of bundles increases.
Time Complexity: O(n)
This means the time to preload bundles grows in direct proportion to how many bundles you have.
[X] Wrong: "Preloading many bundles happens all at once and takes the same time as preloading one."
[OK] Correct: Each bundle requires a separate preload call, so more bundles mean more calls and more time.
Understanding how preload operations scale helps you design efficient loading strategies and shows you can think about resource costs clearly.
"What if we preload bundles in parallel instead of one by one? How would the time complexity change?"