Skip to content

Commit 94489d5

Browse files
javachefacebook-github-bot
authored andcommitted
Add trace markers for onScrollChanged / updateClippingRect (facebook#46412)
Summary: Pull Request resolved: facebook#46412 These are quite useful when investigating scroll performance. Changelog: [internal] Reviewed By: rshest Differential Revision: D62213724 fbshipit-source-id: 3293aaf82584eae8508c748638c47c8b010db58f
1 parent 274f5bf commit 94489d5

File tree

3 files changed

+67
-41
lines changed

3 files changed

+67
-41
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactHorizontalScrollView.java

+33-20
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.facebook.react.views.scroll.ReactScrollViewHelper.HasStateWrapper;
6363
import com.facebook.react.views.scroll.ReactScrollViewHelper.ReactScrollViewScrollState;
6464
import com.facebook.react.views.view.ReactViewBackgroundManager;
65+
import com.facebook.systrace.Systrace;
6566
import java.lang.reflect.Field;
6667
import java.util.ArrayList;
6768
import java.util.List;
@@ -490,24 +491,30 @@ protected void onScrollChanged(int x, int y, int oldX, int oldY) {
490491
FLog.i(TAG, "onScrollChanged[%d] x %d y %d oldx %d oldy %d", getId(), x, y, oldX, oldY);
491492
}
492493

493-
super.onScrollChanged(x, y, oldX, oldY);
494+
Systrace.beginSection(
495+
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactHorizontalScrollView.onScrollChanged");
496+
try {
497+
super.onScrollChanged(x, y, oldX, oldY);
494498

495-
mActivelyScrolling = true;
499+
mActivelyScrolling = true;
496500

497-
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
498-
if (mRemoveClippedSubviews) {
499-
updateClippingRect();
500-
}
501-
if (mPreventReentry) {
502-
return;
501+
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
502+
if (mRemoveClippedSubviews) {
503+
updateClippingRect();
504+
}
505+
if (mPreventReentry) {
506+
return;
507+
}
508+
mPreventReentry = true;
509+
ReactScrollViewHelper.updateStateOnScrollChanged(
510+
this,
511+
mOnScrollDispatchHelper.getXFlingVelocity(),
512+
mOnScrollDispatchHelper.getYFlingVelocity(),
513+
mEnableSyncOnScroll);
514+
mPreventReentry = false;
503515
}
504-
mPreventReentry = true;
505-
ReactScrollViewHelper.updateStateOnScrollChanged(
506-
this,
507-
mOnScrollDispatchHelper.getXFlingVelocity(),
508-
mOnScrollDispatchHelper.getYFlingVelocity(),
509-
mEnableSyncOnScroll);
510-
mPreventReentry = false;
516+
} finally {
517+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
511518
}
512519
}
513520

@@ -783,12 +790,18 @@ public void updateClippingRect() {
783790
return;
784791
}
785792

786-
Assertions.assertNotNull(mClippingRect);
793+
Systrace.beginSection(
794+
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactHorizontalScrollView.updateClippingRect");
795+
try {
796+
Assertions.assertNotNull(mClippingRect);
787797

788-
ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
789-
View contentView = getContentView();
790-
if (contentView instanceof ReactClippingViewGroup) {
791-
((ReactClippingViewGroup) contentView).updateClippingRect();
798+
ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
799+
View contentView = getContentView();
800+
if (contentView instanceof ReactClippingViewGroup) {
801+
((ReactClippingViewGroup) contentView).updateClippingRect();
802+
}
803+
} finally {
804+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
792805
}
793806
}
794807

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollView.java

+32-20
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
import com.facebook.react.views.scroll.ReactScrollViewHelper.HasStateWrapper;
6464
import com.facebook.react.views.scroll.ReactScrollViewHelper.ReactScrollViewScrollState;
6565
import com.facebook.react.views.view.ReactViewBackgroundManager;
66+
import com.facebook.systrace.Systrace;
6667
import java.lang.reflect.Field;
6768
import java.util.List;
6869

@@ -414,24 +415,29 @@ private void scrollToChild(View child) {
414415

415416
@Override
416417
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
417-
super.onScrollChanged(x, y, oldX, oldY);
418+
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactScrollView.onScrollChanged");
419+
try {
420+
super.onScrollChanged(x, y, oldX, oldY);
418421

419-
mActivelyScrolling = true;
422+
mActivelyScrolling = true;
420423

421-
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
422-
if (mRemoveClippedSubviews) {
423-
updateClippingRect();
424-
}
425-
if (mPreventReentry) {
426-
return;
424+
if (mOnScrollDispatchHelper.onScrollChanged(x, y)) {
425+
if (mRemoveClippedSubviews) {
426+
updateClippingRect();
427+
}
428+
if (mPreventReentry) {
429+
return;
430+
}
431+
mPreventReentry = true;
432+
ReactScrollViewHelper.updateStateOnScrollChanged(
433+
this,
434+
mOnScrollDispatchHelper.getXFlingVelocity(),
435+
mOnScrollDispatchHelper.getYFlingVelocity(),
436+
mEnableSyncOnScroll);
437+
mPreventReentry = false;
427438
}
428-
mPreventReentry = true;
429-
ReactScrollViewHelper.updateStateOnScrollChanged(
430-
this,
431-
mOnScrollDispatchHelper.getXFlingVelocity(),
432-
mOnScrollDispatchHelper.getYFlingVelocity(),
433-
mEnableSyncOnScroll);
434-
mPreventReentry = false;
439+
} finally {
440+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
435441
}
436442
}
437443

@@ -543,12 +549,18 @@ public void updateClippingRect() {
543549
return;
544550
}
545551

546-
Assertions.assertNotNull(mClippingRect);
552+
Systrace.beginSection(
553+
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "ReactScrollView.updateClippingRect");
554+
try {
555+
Assertions.assertNotNull(mClippingRect);
547556

548-
ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
549-
View contentView = getContentView();
550-
if (contentView instanceof ReactClippingViewGroup) {
551-
((ReactClippingViewGroup) contentView).updateClippingRect();
557+
ReactClippingViewGroupHelper.calculateClippingRect(this, mClippingRect);
558+
View contentView = getContentView();
559+
if (contentView instanceof ReactClippingViewGroup) {
560+
((ReactClippingViewGroup) contentView).updateClippingRect();
561+
}
562+
} finally {
563+
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
552564
}
553565
}
554566

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewHelper.kt

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ import java.util.concurrent.CopyOnWriteArrayList
3030

3131
/** Helper class that deals with emitting Scroll Events. */
3232
public object ReactScrollViewHelper {
33-
private val TAG = ReactHorizontalScrollView::class.java.simpleName
33+
private val TAG = ReactScrollView::class.java.simpleName
3434
private val DEBUG_MODE = false // ReactBuildConfig.DEBUG
35+
3536
private const val CONTENT_OFFSET_LEFT = "contentOffsetLeft"
3637
private const val CONTENT_OFFSET_TOP = "contentOffsetTop"
3738
private const val SCROLL_AWAY_PADDING_TOP = "scrollAwayPaddingTop"

0 commit comments

Comments
 (0)