Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

native: add query traces to Firebase performance #3852

Merged
merged 13 commits into from
Aug 21, 2024

Conversation

davidisaaclee
Copy link
Contributor

@davidisaaclee davidisaaclee commented Aug 20, 2024

The design of the performance monitoring code is a little abstract – this was necessary due to dependency constraints:

  • @tloncorp/shared got broken after I added @react-native-firebase/perf as a dependency
  • @tloncorp/shared has the feature flag setup, so the code enabling/disabling instrumentation needs to reference shared
  • To measure queries, createQuery (in @tloncorp/shared) seemed like the only reasonable place to hook in. (It seems like use-query should have some kind of global pre/post hooks, but I could not find anything.) So @tloncorp/shared needs to be able to call into the performance monitoring controller.

To resolve:

  • @tloncorp/shared has a performance monitoring controller usePerformanceMonitoringStore that is agnostic to the performance monitoring "endpoint", abstracting that as an injected PerformanceMonitoringEndpoint interface
  • usePerformanceMonitoringStore is used in createQuery to measure queries
  • @tloncorp/app implements a PerformanceMonitoringEndpoint using @react-native-firebase/perf, and registers it on the usePerformanceMonitoringStore via a provider component
  • tlon-mobile mounts the context provider near root, hooking everything up

How did I test?

  • Do we send instrumentation without user content? I clean-installed app, inserted a fake custom trace on a button press, pressed button – checked Firebase console after a delay, no trace recorded. Enabled instrumentation via flag, changed ID of custom trace, triggered that trace, checked console – trace was recorded.
  • Does this instrumentation slow down queries? I set up a button to call getGroup on a real group serially, 800 times; ran it once without any instrumentation code, and once with instrumentation enabled. There was less than 1ms of difference for the averaged query duration.
  • Does this work on Android? Yes, running in Android emulator acts the same as in iOS: does not apparently send traces to Firebase until feature flag is toggled; then, only custom traces are sent to https://console.firebase.google.com/u/2/project/tlon-groups-mobile/performance/app/android:io.tlon.groups/trends (different page than iOS)

Example dashboards

Screenshot 2024-08-21 at 9 21 48 AM

Screenshot 2024-08-21 at 9 23 15 AM

Copy link
Member

@arthyn arthyn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm! curious to see what this does

@davidisaaclee
Copy link
Contributor Author

davidisaaclee commented Aug 21, 2024

added some screenshots of what the Firebase dashboards look like – I think the immediate benefit is seeing when a new release significantly changes the duration or volume of queries. We are currently not using HTTP request traces (I don't know if this makes sense for Tlon – maybe if we restrict to only Tlon hosting endpoints?); and we're not using "screen traces", which supposedly reports "slow rendering / frozen frames" (when I tested this with the basic setup, it seemed to only detect generically-named React Native screens, so I think we'd have to adapt it for our usage).

Screenshot 2024-08-21 at 9 30 47 AM

@davidisaaclee davidisaaclee merged commit 8ef4990 into develop Aug 21, 2024
1 check passed
@davidisaaclee davidisaaclee deleted the dil/firebase-perf branch August 21, 2024 16:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants