fix(gestures): Replace GestureDetectorCompat with lightweight detector to fix ANR#5138
Merged
fix(gestures): Replace GestureDetectorCompat with lightweight detector to fix ANR#5138
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. Bug Fixes 🐛
Internal Changes 🔧Deps
🤖 This preview updates automatically when you update the PR. |
Contributor
Performance metrics 🚀
|
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 310.66 ms | 368.19 ms | 57.53 ms |
| 9054d65 | 330.94 ms | 403.24 ms | 72.30 ms |
| b77456b | 393.26 ms | 441.10 ms | 47.84 ms |
| 96449e8 | 361.30 ms | 423.39 ms | 62.09 ms |
| ee747ae | 357.79 ms | 421.84 ms | 64.05 ms |
| a416a65 | 295.53 ms | 373.74 ms | 78.21 ms |
| ab8a72d | 316.24 ms | 356.38 ms | 40.14 ms |
| 1564554 | 323.06 ms | 336.68 ms | 13.62 ms |
| b3d8889 | 371.69 ms | 432.96 ms | 61.26 ms |
| d15471f | 315.20 ms | 370.22 ms | 55.02 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
| 9054d65 | 1.58 MiB | 2.29 MiB | 723.38 KiB |
| b77456b | 1.58 MiB | 2.12 MiB | 548.11 KiB |
| 96449e8 | 1.58 MiB | 2.11 MiB | 539.35 KiB |
| ee747ae | 1.58 MiB | 2.10 MiB | 530.95 KiB |
| a416a65 | 1.58 MiB | 2.12 MiB | 555.26 KiB |
| ab8a72d | 1.58 MiB | 2.12 MiB | 551.55 KiB |
| 1564554 | 1.58 MiB | 2.20 MiB | 635.33 KiB |
| b3d8889 | 1.58 MiB | 2.10 MiB | 535.06 KiB |
| d15471f | 1.58 MiB | 2.13 MiB | 559.54 KiB |
Previous results on branch: rz/fix/anr-gesture-detector
Startup times
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 85a0af4 | 312.65 ms | 356.14 ms | 43.49 ms |
| d7d285a | 324.00 ms | 357.96 ms | 33.96 ms |
| fdd395a | 304.87 ms | 340.11 ms | 35.24 ms |
App size
| Revision | Plain | With Sentry | Diff |
|---|---|---|---|
| 85a0af4 | 0 B | 0 B | 0 B |
| d7d285a | 0 B | 0 B | 0 B |
| fdd395a | 0 B | 0 B | 0 B |
📲 Install BuildsAndroid
|
markushi
approved these changes
Mar 11, 2026
…stureDetector to fix ANR GestureDetectorCompat internally uses Handler.sendMessage/removeMessages which acquires a synchronized lock on the main thread MessageQueue, plus recordGestureClassification triggers IPC calls. This caused ANRs under load (SDK-CRASHES-JAVA-596, 175K+ occurrences). Replace with a minimal custom detector that only detects click, scroll, and fling without any Handler scheduling, MessageQueue contention, or IPC overhead. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…velocity data Matches GestureDetector behavior: if consecutive ACTION_DOWN events arrive without an intervening ACTION_UP/ACTION_CANCEL, stale motion data could bleed into fling detection. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…check UserInteractionIntegration gated itself on GestureDetectorCompat being available via classloader check, but SentryGestureDetector only uses Android SDK classes. Remove the check so the integration works without androidx.core. Also remove the stale proguard -keep rule. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Keep VelocityTracker alive across gesture cycles instead of obtain/recycle churn on every gesture. Add release() method called from SentryWindowCallback.stopTracking() to prevent native resource leaks when activity is destroyed mid-gesture. Also fix broken Javadoc @link to removed dependency, change onTouchEvent return to void, and remove redundant null check. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1a7624e to
e9db3cb
Compare
When a second finger touches the screen (ACTION_POINTER_DOWN), cancel tap detection by setting isInTapRegion to false. Previously, pinch-to-zoom gestures where the first finger stayed still would incorrectly trigger onSingleTapUp, producing false click breadcrumbs. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add local btrace-perfetto skill for capturing and comparing Perfetto traces on Android devices using btrace 3.0. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Workflow skill that automates capturing and comparing Perfetto traces using btrace 3.0 on Android devices. Includes a Perfetto UI viewer template with SQL query deep-linking via postMessage API. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 76e9b72. Configure here.
Use release builds for accurate profiling, add ProGuard keep rules for btrace and Sentry class names, increase trace duration to 30s, and play a Ping sound synced to the actual trace start. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…rison Prefer debug builds for richer tracing instrumentation (Handler, MessageQueue, Lock slices). Add trace_processor prerequisite for local querying. Add Step 6 with SQL queries and comparison table generation. Include sampling rate reference and additional troubleshooting entries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
…ied swipes The ACTION_POINTER_DOWN handler suppressed taps but not flings. When the last finger lifts quickly after a pinch-to-zoom, the velocity check in ACTION_UP could fire onFling, causing SentryGestureListener to misclassify the gesture as a swipe breadcrumb. Add ignoreUpEvent flag mirroring GestureDetector's mIgnoreNextUpEvent to skip the entire UP handler after multi-touch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.


Summary
GestureDetectorCompatwith a custom lightweightSentryGestureDetectorinSentryWindowCallbackto fix ANR SDK-CRASHES-JAVA-596 (175K+ occurrences, 574 users)GestureDetectorCompatinternally usesHandler.sendMessage/removeMessageswhich acquires asynchronizedlock on the main thread'sMessageQueue, plusrecordGestureClassification()triggers IPC/binder calls — both cause contention under loadSentryGestureListeneruses), eliminating all Handler scheduling, MessageQueue lock contention, and IPC overheadTest plan
SentryGestureDetectorTestwith 7 test cases: tap, no-tap, scroll with deltas, fling, slow release, cancel cleanup, sequential gesture resetSentryWindowCallbackTest(4 tests) passesSentryGestureListenerTestsuite passes./gradlew :sentry-android-core:testDebugUnitTestpasses🤖 Generated with Claude Code