Why file storage is needed in Firebase - Performance Analysis
We want to understand how storing files in Firebase grows in cost as we add more files.
How does the number of files affect the work Firebase does?
Analyze the time complexity of uploading multiple files to Firebase Storage.
const uploadFiles = async (files) => {
for (const file of files) {
const storageRef = firebase.storage().ref().child(file.name);
await storageRef.put(file);
}
};
This code uploads each file one by one to Firebase Storage.
Look at what repeats as we add more files.
- Primary operation: Uploading a single file using
storageRef.put(file). - How many times: Once for each file in the list.
Each new file means one more upload operation.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 uploads |
| 100 | 100 uploads |
| 1000 | 1000 uploads |
Pattern observation: The number of uploads grows directly with the number of files.
Time Complexity: O(n)
This means the work grows in a straight line as you add more files.
[X] Wrong: "Uploading many files takes the same time as uploading one file."
[OK] Correct: Each file needs its own upload, so more files mean more work and time.
Understanding how file uploads scale helps you design apps that handle many files smoothly.
"What if we upload files in parallel instead of one by one? How would the time complexity change?"