initial sync of "limit to last N" query taking much longer when the array size gets larger?

107 views
Skip to first unread message

James Manning

unread,
Mar 22, 2015, 3:49:26 PM3/22/15
to fireba...@googlegroups.com
I have a firebase array that a node process appends to and browser clients query with limitToLast(20).  What I noticed was that as the array grew significantly larger, the amount of time it took the client to get the initial 20 items took longer and longer.  It felt linear, almost like the server side is walking through the array from the front to figure out the last 20 items.  Once the initial sync is done, the speed of client updates appears to be the same regardless of the array size.

Is this intentional / By Design?  Is it a result of firebase not having 'real' array support?  Is there anything I can do (outside of keeping the array smaller) to speed up the initial sync?

Thanks, everyone!!

James

Jonny Dimond

unread,
Mar 24, 2015, 12:58:40 PM3/24/15
to fireba...@googlegroups.com
Hey James,

this might be due to a missing index. If you call orderByChild/orderByValue, you need to add an index to your Firebase rules. If you don't do that, limitToLast will indeed be very slow and inefficient. Let us know if you have already added an index to see if there is a different underlying issue. Thanks.

Jonny

Emil Anticevic

unread,
Mar 24, 2015, 4:35:10 PM3/24/15
to fireba...@googlegroups.com
Jonny - so if you use orderByKey().limitToLast(10) the linear slowdown should NOT be the case?

Jonny Dimond

unread,
Mar 24, 2015, 4:59:38 PM3/24/15
to fireba...@googlegroups.com
In general orderByKey().limitToLast(10) should not see a linear slowdown. Keep in mind that there might be caching effects here and for an app that is not used often the first listen of *any* client might involve a slowdown compared to subsequent listens...

Emil Anticevic

unread,
Mar 24, 2015, 9:13:27 PM3/24/15
to firebase-talk
Ah ok. Is the caching done per "tree" or per app?

--
You received this message because you are subscribed to a topic in the Google Groups "Firebase Google Group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/firebase-talk/ZKrHz8sGd4I/unsubscribe.
To unsubscribe from this group and all its topics, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/fb6b94c7-7a46-4aa0-959b-1411d66229ff%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Jonny Dimond

unread,
Mar 24, 2015, 9:38:33 PM3/24/15
to fireba...@googlegroups.com
The caching is an underlying implementation detail so I won't go into details here. If you think that your queries are slower than expected, please ping us at sup...@firebase.com and we can investigate further. Thanks.
Reply all
Reply to author
Forward
0 new messages