CSFrequency / react-firebase-hooks

React Hooks for Firebase.
Apache License 2.0
3.55k stars 304 forks source link

Questions about performance (bandwidth usage) #247

Closed NathanC closed 1 year ago

NathanC commented 2 years ago

I want to make sure I'm not using more bandwidth than I intend

If I have different components that are each using useList for firebase database, with

Will firebase fetch the data twice, or does the backend websocket logic prevent loading the same queries/fetching the same data at once?

Thanks in advance!

chrisbianca commented 1 year ago

@NathanC Apologies for the delay. Behind the scenes the hooks library uses the underlying Firebase library so will behave as per the documentation for Firebase. This is probably a better question to ask on the Firebase forums as I don't want to give you misinformation.

Abacaxi-Nelson commented 1 year ago

@NathanC did you have the answer ? same use case, i need realtime profile information in multiple places but i dont know if under the hood, kind of deduplication is done

NathanC commented 1 year ago

@Abacaxi-Nelson No, I'm not entirely sure, have been focused on other stuff (and I've switched from realtime database -> firestore since making this issue). I would like to dig into this more later and find out for sure, but it hasn't been much of a priority.

I will say, @chrisbianca this isn't quite an upstream question, it's also a question of how this library's hooks interact with the underlying firebase SDK. i.e., if hooks from different contexts have some shared notion of underlying references, and their lifecycle in regards to the SDK. It does matter how the underlying SDK is dealing with common references and how it determines that, but it also matters how this library leverages the SDK from different contexts.

NathanC commented 4 months ago

@chrisbianca I'm revisiting this. Your initial answer didn't really get to my question—I'm trying to understand what happens when leaving a component and coming back to the same component, with the same query. Will it result in additional reads to Firestore? If so, is there any way to cache a query so that it will keep the connections open?

Firestore reads are expensive so this matters a lot.