3

I want to get a list (potentially 100k+ entries) as read-only values.

I can use:

firebaseRef.once('value', function(dataSnapshot) {
    // handle read data.
});

Or I could get the data by issuing a GET request to a Firebase endpoint:

https://docs-examples.firebaseio.com/rest/saving-data/fireblog/posts.json

In this read-only scenario, the REST API seems to be consistently faster than using the library. Particularly on larger data sets.

Why is this? If I only want to read data, is there any reason not to use the GET request method?

1
  • 1
    The JavaScript SDK is primarily built to synchronize data in realtime. If you don't need that and get better (in your definition of what that means, e.g. "Faster") results with the REST endooint, by all means use the REST endpoint. Commented Feb 20, 2015 at 14:34

1 Answer 1

3

firebaseRef.once() uses a WebSocket. It takes as much time to set up as a repeating event observer, and it doesn't benefit from the cacheability of a GET request. It also makes use of the global firebase auth state, which is more convenient but less flexible than the auth parameter of a REST request.

If you are already setting up a WebSocket connection for repeating event handlers, once will sometimes be the most convenient way to get the latest data for something that wouldn't have benefitted from cacheing anyway. But sometimes you have to dip into the REST layer to fully optimize performance.

Sign up to request clarification or add additional context in comments.

2 Comments

Is it just setting up one WebSocket for the whole child node? The time difference I notice between GET and the library call can be as much as 10 seconds on larger sets.
The library has some facilities for switching protocols, or using multiple connections for multiple data objects. Sometimes you see several sockets open at once when listening to several objects. But I don't think it can ever split a single request across multiple sockets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.