Update: Now we also address this issue in the AskFirebase episode.
Loading many items from Firebase does not have to be slow, because you can pipelining requests. But your code makes this impossible, which will really lead to suboptimal performance.
In your code, you request an item from the server, wait for that item to return, and then download the next one. In a simplified sequence diagram that looks like this:
Your app Firebase Database -- request item 1 --> SL eo ra vd ei <- return item 1 -- rn g -- request item 2 --> SL eo ra vd ei rn <- return item 2 -- g -- request item 3 --> . . . -- request item 30--> SL eo ra vd ei rn g <- return item 30 --
In this scenario, you expect 30 times your time to capture + 30 times the time it takes to load data from disk. If (for simplicity) we say that roundtrips take 1 second, and loading an item from disk also takes one second, which is less than 30 * (1 + 1) = 60 seconds.
In Firebase applications, you will get much better performance if you send all the requests (or at least a reasonable number of them) at once:
Your app Firebase Database -- request item 1 --> -- request item 2 --> SL -- request item 3 --> eo . ra . vd . ei -- request item 30--> rn g <- return item 1 -- <- return item 2 -- <- return item 3 -- . . . <- return item 30 --
If we again take the 1 second circuit and 1 second boot, you wait 30 * 1 + 1 = 31 seconds.
So: all requests go through the same connection. Given this, the only difference between get(1) , get(2) , get(3) and getAll([1,2,3]) are some overhead for frames.
I installed jsbin to demonstrate the behavior . The data model is very simple, but it shows the difference.
function loadVideosSequential(videoIds) { if (videoIds.length > 0) { db.child('videos').child(videoIds[0]).once('value', snapshot => { if (videoIds.length > 1) { loadVideosSequential(videoIds.splice(1), callback) } }); } } function loadVideosParallel(videoIds) { Promise.all( videoIds.map(id => db.child('videos').child(id).once('value')) ); }
For comparison: sequential loading of 64 elements takes 3.8 seconds on my system, and when loading them pipeline (since the Firebase client is executed initially), it takes 600 ms. The exact numbers will depend on your connection (latency and bandwidth), but the pipelined version should always be significantly faster.