0
0
Firebasecloud~5 mins

Bundle preloading in Firebase - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Bundle preloading
O(n)
Understanding Time 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?

Scenario Under Consideration

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 Repeating Operations

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.
How Execution Grows With Input

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
1010 preload calls
100100 preload calls
10001000 preload calls

Pattern observation: The number of preload operations grows linearly as the number of bundles increases.

Final Time Complexity

Time Complexity: O(n)

This means the time to preload bundles grows in direct proportion to how many bundles you have.

Common Mistake

[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.

Interview Connect

Understanding how preload operations scale helps you design efficient loading strategies and shows you can think about resource costs clearly.

Self-Check

"What if we preload bundles in parallel instead of one by one? How would the time complexity change?"