perf(replay): Defer ReplayIntegration.start() off the main thread#5474
Draft
runningcode wants to merge 2 commits into
Draft
perf(replay): Defer ReplayIntegration.start() off the main thread#5474runningcode wants to merge 2 commits into
runningcode wants to merge 2 commits into
Conversation
Move the expensive work in ReplayIntegration.start() (capture strategy creation, recorder start, root view listener registration) to the executor service, keeping only the lightweight state checks and lifecycle transition synchronous. This saves ~16ms on the main thread during SentryAndroid.init() (measured on Pixel 3). The registerRootViewListeners() call is posted to the main looper handler since it triggers View operations via OnRootViewsChangedListener. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
||
| ### Improvements | ||
|
|
||
| - Improve SDK init performance by deferring `ReplayIntegration.start()` off the main thread ([#5474](https://github.com/getsentry/sentry-java/pull/5474)) |
Contributor
There was a problem hiding this comment.
- 🚫 The changelog entry seems to be part of an already released section
## 8.43.0.
Consider moving the entry to the## Unreleasedsection, please.
📲 Install BuildsAndroid
|
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a5ab36f | 316.83 ms | 394.54 ms | 77.71 ms |
| e63ad34 | 336.55 ms | 406.79 ms | 70.23 ms |
| ad8da22 | 362.98 ms | 453.94 ms | 90.96 ms |
| 70118e9 | 380.00 ms | 475.72 ms | 95.72 ms |
| 2124a46 | 319.19 ms | 415.04 ms | 95.85 ms |
| b3d8889 | 371.84 ms | 447.49 ms | 75.65 ms |
| cf708bd | 434.73 ms | 502.96 ms | 68.22 ms |
| ab8a72d | 316.24 ms | 356.38 ms | 40.14 ms |
| d5a29b6 | 298.62 ms | 391.78 ms | 93.16 ms |
| d15471f | 379.40 ms | 470.76 ms | 91.36 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| a5ab36f | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| e63ad34 | 0 B | 0 B | 0 B |
| ad8da22 | 1.58 MiB | 2.29 MiB | 719.83 KiB |
| 70118e9 | 1.58 MiB | 2.29 MiB | 719.84 KiB |
| 2124a46 | 1.58 MiB | 2.12 MiB | 551.51 KiB |
| b3d8889 | 1.58 MiB | 2.10 MiB | 535.07 KiB |
| cf708bd | 1.58 MiB | 2.11 MiB | 539.71 KiB |
| ab8a72d | 1.58 MiB | 2.12 MiB | 551.55 KiB |
| d5a29b6 | 1.58 MiB | 2.12 MiB | 549.37 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
Move the expensive work in
ReplayIntegration.start()(capture strategy creation, recorder start, root view listener registration) to the executor service background thread. The lightweight state checks and lifecycle transition (lifecycle.currentState = STARTED) remain synchronous so thatisRecording()returns the correct value immediately.registerRootViewListeners()is posted to the main looper handler since it triggers View operations (e.g.addOnLayoutChangeListener) viaOnRootViewsChangedListener.💡 Motivation and Context
Perfetto traces on a Pixel 3 show
ReplayIntegration.start()taking ~16ms on the main thread duringSentryAndroid.init(). Sincestart()is called after init is complete and doesn't need to block the caller, the heavy work can be deferred to a background thread.💚 How did you test it?
:sentry-android-core:testDebugUnitTest— all 22 tests pass:sentry-android-replay:testDebugUnitTest— all 209 tests pass (includingReplayIntegrationTest,ReplayIntegrationWithRecorderTest,ReplaySmokeTest)📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps