getsentry / sentry-java

A Sentry SDK for Java, Android and other JVM languages.
https://docs.sentry.io/
MIT License
1.14k stars 430 forks source link

Offload NDK Scope sync to background thread #3046

Open markushi opened 9 months ago

markushi commented 9 months ago

Problem Statement

As of now any context data (user, breadcrumb, tags, ...) is synced to sentry-native on the calling thread. The calling thread might be the main thread, which is not optimal.

Solution Brainstorm

We should offload the scope sync to a background thread, ensuring we're not spending too much time on the main thread.

markushi commented 8 months ago

Let's be aware if the sync happens on a background thread, the data won't be available immediately on the NDK side. E.g. when next line in code performs JNI call.

markushi commented 8 months ago

Let's talk about this in the next sentry-native sync.

markushi commented 8 months ago

Let's check the top-level attributes in the data bag: If it's only primitives sync the breadcrumbs directly, otherwise offload to a background thread.

romtsn commented 2 months ago

Let's also profile/compare the timings of syncing this with only primitives. If it's quick enough we could still do that on the main thread, otherwise offload to a bg thread