David Gilbertson
David Gilbertson

Reputation: 4883

Firebase child syntax performance

I'm starting a project and setting the code style guide. I like the second of the two below, but I'm wondering if there is a difference in the way these two statements are executed? Is the second one slower, or is the whole chain evaluated before any call to the database happens? (I only see a single frame in the socket)

Style 1:

db.child(`data/projects/${currentProject}/boxes/${newBoxId}`).set(true);

Style 2:

  db
    .child('data')
    .child('projects')
    .child(currentProject)
    .child('boxes')
    .child(newBoxId)
    .set(true);

Upvotes: 0

Views: 104

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 600100

There is no performance difference between the two.

Calling child() does not require the client to connect to the server, it's a pure client-side operation. So you can do whatever is most readable in your code.

If I have a set of static segments in the path, I typically combine them in a single child() call. But when there is a dynamic segment, I prefer to put that into its own child() call to prevent having to concatenate strings.

ref.child('users').child(authData.uid).child('documents/passport').on('value'...

Upvotes: 1

Related Questions