Skip to content

Conversation

@markushi
Copy link
Member

@markushi markushi commented Feb 13, 2025

📜 Description

We don't seem to be able to get rid of calling getConnectionStatus() on connectivity change, as the NetworkCallback seems to fire for any network, e.g. reporting a disconnect of WIFI, although Cellular connection is still available.

But I noticed every internal IConnectionStatusObserver was tied to it's own NetworkCallback, causing us to call getConnectionStatus() per change per observer - which quickly blows our number of IPC calls up.

So instead let's have a single NetworkCallback, call getConnectionStatus() once per network change and then broadcast the state to all observers. This should already reduce the number of IPC calls by 3.

💡 Motivation and Context

Less IPC calls
Fixes #4053

💚 How did you test it?

📝 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

@github-actions
Copy link
Contributor

github-actions bot commented Feb 13, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 426.60 ms 436.61 ms 10.01 ms
Size 1.58 MiB 2.21 MiB 641.48 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
c2c78de 415.28 ms 505.08 ms 89.80 ms

App size

Revision Plain With Sentry Diff
c2c78de 1.58 MiB 2.21 MiB 640.27 KiB

Previous results on branch: markushi/enh/reduce-number-of-ipc-calls-connection-status-provider

Startup times

Revision Plain With Sentry Diff
f6eabd8 471.24 ms 526.07 ms 54.83 ms
feeddf1 424.94 ms 463.50 ms 38.56 ms

App size

Revision Plain With Sentry Diff
f6eabd8 1.58 MiB 2.21 MiB 641.13 KiB
feeddf1 1.58 MiB 2.21 MiB 641.12 KiB

this.logger = logger;
this.buildInfoProvider = buildInfoProvider;
this.registeredCallbacks = new HashMap<>();
this.connectionStatusObservers = new ArrayList<>();
Copy link
Member

Choose a reason for hiding this comment

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

just thinking if it's better to use CopyOnWrite here to avoid potential lock contention?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's fine, I'm using a lock mechanism for safe access and there aren't many writes to this list: In my testing there were 3 listeners attached.

Copy link
Member

@romtsn romtsn left a comment

Choose a reason for hiding this comment

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

LGTM, very simple change with a very big impact 🚀

@romtsn
Copy link
Member

romtsn commented Feb 14, 2025

Oh btw, I also thought of maybe persisting the last known connection status in AndroidConnectionStatusProvider so we don't have to do IPC (getActiveNetworkInfo) when we want to know the current status at a certain moment in time? In that case we'd probably have to registerNetworkCallback in the AndroidConnectionStatusProvider ctor so we always have access to the last known state after the SDK is initialized.

@markushi markushi merged commit d653590 into main Feb 24, 2025
40 checks passed
@markushi markushi deleted the markushi/enh/reduce-number-of-ipc-calls-connection-status-provider branch February 24, 2025 10:18
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.

Reduce IPC calls performed when checking connectivity

3 participants