Skip to content

fix(gestures): Use peekDecorView to not force view hierarchy construction#5134

Merged
romtsn merged 3 commits intomainfrom
rz/fix/gesture-listener-anr
Mar 3, 2026
Merged

fix(gestures): Use peekDecorView to not force view hierarchy construction#5134
romtsn merged 3 commits intomainfrom
rz/fix/gesture-listener-anr

Conversation

@romtsn
Copy link
Member

@romtsn romtsn commented Mar 2, 2026

SentryGestureListener was calling window.getDecorView() which forces the creation of the entire view hierarchy if it hasn't been created yet. This can cause ANRs on the main thread, as seen in production with ~21k occurrences affecting ~195 users.

The ANR originates from SentryGestureListener.onScrollgetDecorView() triggering expensive view hierarchy construction during touch event processing.

Switches to window.peekDecorView() which returns null if the decor view hasn't been created yet, instead of forcing its creation. The existing null-check already handles this case gracefully by logging and returning early.

Fixes https://sentry.sentry.io/issues/6138840301/

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

  • (otel) Create sentry-opentelemetry-otlp module for combining OpenTelemetry SDK OTLP export with Sentry SDK by adinauer in #5100
  • (screenshot) Add screenshot masking using view hierarchy by romtsn in #5077

Bug Fixes 🐛

  • (android) Remove AndroidRuntimeManager to prevent ANRs during SDK init by romtsn in #5127
  • (gestures) Use peekDecorView to not force view hierarchy construction by romtsn in #5134
  • (init) Reduce allocations and bytecode instructions during Sentry.init by romtsn in #5135
  • (transport) Handle HTTP 413 with actionable log and use send_error for HTTP errors by adinauer in #5115
  • Trim DSN string before URI parsing by adinauer in #5113
  • Safe unregister SystemEventsBroadcastReceiver by kollesnica1337 in #5106

Internal Changes 🔧

Deps

  • Bump getsentry/craft from 2.21.7 to 2.23.1 by dependabot in #5129
  • Update Native SDK to v0.13.1 by github-actions in #5104
  • Bump actions/upload-artifact from 6 to 7 by dependabot in #5130
  • Bump actions/download-artifact from 7 to 8 by dependabot in #5132
  • Bump gradle/actions from 5.0.1 to 5.0.2 by dependabot in #5131
  • Bump github/codeql-action from 4.32.2 to 4.32.4 by dependabot in #5109
  • Bump getsentry/craft from 2.21.2 to 2.21.7 by dependabot in #5110

🤖 This preview updates automatically when you update the PR.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 318.14 ms 377.45 ms 59.31 ms
Size 1.58 MiB 2.29 MiB 722.91 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
91bb874 310.68 ms 359.24 ms 48.56 ms
e59e22a 368.02 ms 432.00 ms 63.98 ms
fc5ccaf 279.11 ms 353.34 ms 74.23 ms
d15471f 315.20 ms 370.22 ms 55.02 ms
d15471f 286.65 ms 314.68 ms 28.03 ms
d15471f 342.08 ms 415.44 ms 73.35 ms
ad8da22 314.38 ms 352.29 ms 37.91 ms
cf708bd 434.73 ms 502.96 ms 68.22 ms
abfcc92 309.54 ms 380.32 ms 70.78 ms
91bb874 314.47 ms 440.00 ms 125.53 ms

App size

Revision Plain With Sentry Diff
91bb874 1.58 MiB 2.13 MiB 559.07 KiB
e59e22a 1.58 MiB 2.20 MiB 635.34 KiB
fc5ccaf 1.58 MiB 2.13 MiB 557.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
d15471f 1.58 MiB 2.13 MiB 559.54 KiB
ad8da22 1.58 MiB 2.29 MiB 719.83 KiB
cf708bd 1.58 MiB 2.11 MiB 539.71 KiB
abfcc92 1.58 MiB 2.13 MiB 557.31 KiB
91bb874 1.58 MiB 2.13 MiB 559.07 KiB

Previous results on branch: rz/fix/gesture-listener-anr

Startup times

Revision Plain With Sentry Diff
ae1cec9 311.94 ms 356.06 ms 44.12 ms

App size

Revision Plain With Sentry Diff
ae1cec9 1.58 MiB 2.29 MiB 723.15 KiB

@romtsn romtsn marked this pull request as ready for review March 2, 2026 11:53
Copy link
Member

@adinauer adinauer left a comment

Choose a reason for hiding this comment

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

LGTM

@romtsn romtsn merged commit 01221e2 into main Mar 3, 2026
63 of 65 checks passed
@romtsn romtsn deleted the rz/fix/gesture-listener-anr branch March 3, 2026 11:21
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