-
-
Notifications
You must be signed in to change notification settings - Fork 455
perf(connectivity): Cache network capabilities and status to reduce IPC calls #4560
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
Conversation
} | ||
} | ||
lastCacheUpdateTime = timeProvider.getCurrentTimeMillis(); | ||
|
||
options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could drop this log call, but I thought it might be very useful to investigate potential issues. Under the hood getConnectionStatus and getConnectionType are very lightweight for a cache NetworkCapabilities instance, they just do bitmask operations to get the transport and capability
Performance metrics 🚀
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! I've left a nit about the transports, but looks good otherwise!
...core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java
Outdated
Show resolved
Hide resolved
...core/src/main/java/io/sentry/android/core/internal/util/AndroidConnectionStatusProvider.java
Show resolved
Hide resolved
capabilities[0] = NetworkCapabilities.NET_CAPABILITY_INTERNET; | ||
if (buildInfoProvider.getSdkInfoVersion() >= Build.VERSION_CODES.M) { | ||
capabilities[1] = NetworkCapabilities.NET_CAPABILITY_VALIDATED; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Static Array Mutation Causes Network Capability Inconsistency
The static final
capabilities
array is mutated in the AndroidConnectionStatusProvider
constructor based on instance-specific SDK versions. This creates a race condition where multiple instances, particularly those with different API levels, overwrite the shared static array, leading to inconsistent and incorrect network capability checks across all instances.
Locations (1)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While there might be multiple SDK instances running at a time, it's not possible for them to run on different API levels at the same time, because the device can only target one API level at a time.
📜 Description
onLost
/onUnavailable
would immediately send DISCONNECTED now as opposed to retrievingconnectionStatus
againisSignificantChange
check, becauseonNetworkCapabilitiesChanged
can be called many times due to bandwidth change/etc. and we're only interested in transport/connectivity changesRan a test with perfetto to count the number of binder calls, and these are the results:
Before (83 binder calls from SentryExecService)
After (5 binder calls from SentryExecService)
💡 Motivation and Context
Fixes #4200
💚 How did you test it?
Manually + automated
📝 Checklist
sendDefaultPII
is enabled.🔮 Next steps