Skip to content

Commit 5b790bc

Browse files
authored
perf(user-interactions): Make user interaction tracing faster and allocate less (#4347)
* perf(user-interactions): Make user interaction tracing faster and allocate less * Changelog
1 parent cdfac96 commit 5b790bc

File tree

5 files changed

+15
-7
lines changed

5 files changed

+15
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
- Fix unregister `SystemEventsBroadcastReceiver` when entering background ([#4338](https://github.com/getsentry/sentry-java/pull/4338))
1616
- This should reduce ANRs seen with this class in the stack trace for Android 14 and above
1717

18+
### Improvements
19+
20+
- Make user interaction tracing faster and do fewer allocations ([#4347](https://github.com/getsentry/sentry-java/pull/4347))
21+
1822
## 8.8.0
1923

2024
### Features

sentry-android-core/src/main/java/io/sentry/android/core/internal/gestures/ViewUtils.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.sentry.internal.gestures.GestureTargetLocator;
99
import io.sentry.internal.gestures.UiElement;
1010
import java.util.LinkedList;
11+
import java.util.List;
1112
import java.util.Queue;
1213
import org.jetbrains.annotations.ApiStatus;
1314
import org.jetbrains.annotations.NotNull;
@@ -60,6 +61,7 @@ private static boolean touchWithinBounds(
6061
final float y,
6162
final UiElement.Type targetType) {
6263

64+
final List<GestureTargetLocator> locators = options.getGestureTargetLocators();
6365
final Queue<View> queue = new LinkedList<>();
6466
queue.add(decorView);
6567

@@ -79,7 +81,8 @@ private static boolean touchWithinBounds(
7981
}
8082
}
8183

82-
for (GestureTargetLocator locator : options.getGestureTargetLocators()) {
84+
for (int i = 0; i < locators.size(); i++) {
85+
final GestureTargetLocator locator = locators.get(i);
8386
final @Nullable UiElement newTarget = locator.locate(view, x, y, targetType);
8487
if (newTarget != null) {
8588
if (targetType == UiElement.Type.CLICKABLE) {

sentry-compose/proguard-rules.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
-keepnames class androidx.compose.foundation.CombinedClickableElement
1414
-keepnames class androidx.compose.foundation.ScrollingLayoutElement
1515
-keepnames class androidx.compose.ui.platform.TestTagElement { *; }
16-
-keepnames class io.sentry.compose.SentryModifier.SentryTagModifierNodeElement { *; }
16+
-keepnames class io.sentry.compose.SentryModifier$SentryTagModifierNodeElement { *; }
1717

1818
# R8 will warn about missing classes if people don't have androidx.compose-navigation on their
1919
# classpath, but this is fine, these classes are used in an internal class which is only used when

sentry-compose/src/androidMain/kotlin/io/sentry/compose/SentryComposeHelper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ internal class SentryComposeHelper(logger: ILogger) {
1818
loadField(logger, "androidx.compose.ui.platform.TestTagElement", "tag")
1919

2020
private val sentryTagElementField: Field? =
21-
loadField(logger, "io.sentry.compose.SentryModifier.SentryTagModifierNodeElement", "tag")
21+
loadField(logger, "io.sentry.compose.SentryModifier${'$'}SentryTagModifierNodeElement", "tag")
2222

2323
fun extractTag(modifier: Modifier): String? {
24-
val type = modifier.javaClass.canonicalName
24+
val type = modifier.javaClass.name
2525
// Newer Jetpack Compose uses TestTagElement as node elements
2626
// See
2727
// https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/platform/TestTag.kt;l=34;drc=dcaa116fbfda77e64a319e1668056ce3b032469f
@@ -31,7 +31,7 @@ internal class SentryComposeHelper(logger: ILogger) {
3131
) {
3232
val value = testTagElementField.get(modifier)
3333
return value as String?
34-
} else if ("io.sentry.compose.SentryModifier.SentryTagModifierNodeElement" == type &&
34+
} else if ("io.sentry.compose.SentryModifier${'$'}SentryTagModifierNodeElement" == type &&
3535
sentryTagElementField != null
3636
) {
3737
val value = sentryTagElementField.get(modifier)

sentry-compose/src/androidMain/kotlin/io/sentry/compose/gestures/ComposeGestureTargetLocator.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public class ComposeGestureTargetLocator(private val logger: ILogger) : GestureT
7070
var isScrollable = false
7171

7272
val modifiers = node.getModifierInfo()
73-
for (modifierInfo in modifiers) {
73+
for (index in modifiers.indices) {
74+
val modifierInfo = modifiers[index]
7475
val tag = composeHelper!!.extractTag(modifierInfo.modifier)
7576
if (tag != null) {
7677
lastKnownTag = tag
@@ -93,7 +94,7 @@ public class ComposeGestureTargetLocator(private val logger: ILogger) : GestureT
9394
} else {
9495
val modifier = modifierInfo.modifier
9596
// Newer Jetpack Compose 1.5 uses Node modifiers for clicks/scrolls
96-
val type = modifier.javaClass.canonicalName
97+
val type = modifier.javaClass.name
9798
if ("androidx.compose.foundation.ClickableElement" == type ||
9899
"androidx.compose.foundation.CombinedClickableElement" == type
99100
) {

0 commit comments

Comments
 (0)