Skip to content

perf(connectivity): Have only one NetworkCallback active at a time #4562

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

Open
wants to merge 3 commits into
base: rz/fix/diff-battery-crumbs
Choose a base branch
from

Conversation

romtsn
Copy link
Member

@romtsn romtsn commented Jul 18, 2025

📜 Description

  • Have only single NetworkCallback registered at a time
    • Multi-cast it to the internal child NetworkCallbacks (NetworkBreadcrumbsIntegration)
  • Remove executor in NetworkBreadcrumbsIntegration since we just add a callback to the list now instead of doing any IPC
  • While testing it I noticed replay wasn't always catching network_available breadcrumb due to timing issues, so I special-cased it in this PR too

Event example: https://sentry-sdks.sentry.io/issues/6560149804/events/960094050aa341cca6ac9d0c175f699e/
Replay example: https://sentry-sdks.sentry.io/explore/replays/fff819393dd44cfa9a06b54255664529

💡 Motivation and Context

Less IPC

💚 How did you test it?

Manually + automated

📝 Checklist

  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

scopes, buildInfoProvider, options.getDateProvider());

final boolean registered =
AndroidConnectionStatusProvider.addNetworkCallback(
Copy link
Member Author

Choose a reason for hiding this comment

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

one caveat: This now will not emit AVAILABLE and CAPABILITIES_CHANGED callbacks immediately after registration as opposed to calling ConnectivityManager.registerDefaultNetworkCallback.

But I think it's fine and how it should be - previously any event would always start with NETWORK_AVAILABLE breadcrumb, which could have been misleading, now we're actually adding breadcrumbs whenever there's a change.

if (scopes != null && options != null) {
if (scopes != null
&& options != null
&& status != IConnectionStatusProvider.ConnectionStatus.DISCONNECTED) {
Copy link
Member Author

Choose a reason for hiding this comment

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

kind of unrelated to this PR, but I noticed that we also submit a task even if the status was DISCONNECTED, which was unnecessary since we'd anyway bail out in the submitted task itself.

Copy link
Contributor

github-actions bot commented Jul 18, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 471.84 ms 493.10 ms 21.26 ms
Size 1.58 MiB 2.09 MiB 520.98 KiB

Baseline results on branch: rz/fix/diff-battery-crumbs

Startup times

Revision Plain With Sentry Diff
b0bed47 400.72 ms 441.62 ms 40.90 ms
4522edb 390.10 ms 421.50 ms 31.40 ms
551ddda 414.94 ms 476.12 ms 61.19 ms

App size

Revision Plain With Sentry Diff
b0bed47 1.58 MiB 2.09 MiB 520.80 KiB
4522edb 1.58 MiB 2.09 MiB 520.79 KiB
551ddda 1.58 MiB 2.09 MiB 520.78 KiB

Previous results on branch: rz/perf/single-network-callback

Startup times

Revision Plain With Sentry Diff
c2f723e 382.31 ms 432.96 ms 50.65 ms

App size

Revision Plain With Sentry Diff
c2f723e 1.58 MiB 2.09 MiB 520.98 KiB

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