-
Notifications
You must be signed in to change notification settings - Fork 25.1k
Setup a Macrobenchmark for RNTester #49482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /build |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.android.test) | ||
| alias(libs.plugins.kotlin.android) | ||
| } | ||
|
|
||
| android { | ||
| namespace = "com.example.benchmark" | ||
| compileSdk = 35 | ||
|
|
||
| defaultConfig { | ||
| minSdk = 24 | ||
| targetSdk = 35 | ||
|
|
||
| testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
| } | ||
|
|
||
| buildTypes { | ||
| // This benchmark buildType is used for benchmarking, and should function like your | ||
| // release build (for example, with minification on). It"s signed with a debug key | ||
| // for easy local/CI testing. | ||
| create("benchmark") { | ||
| isDebuggable = true | ||
| signingConfig = getByName("debug").signingConfig | ||
| matchingFallbacks += listOf("release") | ||
| } | ||
| } | ||
|
|
||
| flavorDimensions += listOf("vm") | ||
| productFlavors { | ||
| create("hermes") { dimension = "vm" } | ||
| create("jsc") { dimension = "vm" } | ||
| } | ||
|
|
||
| targetProjectPath = ":packages:rn-tester:android:app" | ||
| experimentalProperties["android.experimental.self-instrumenting"] = true | ||
| } | ||
|
|
||
| dependencies { | ||
| implementation(libs.androidx.junit) | ||
| implementation(libs.androidx.espresso.core) | ||
| implementation(libs.androidx.uiautomator) | ||
| implementation(libs.androidx.benchmark.macro.junit4) | ||
| } | ||
|
|
||
| androidComponents { beforeVariants(selector().all()) { it.enable = it.buildType == "benchmark" } } |
1 change: 1 addition & 0 deletions
1
packages/rn-tester/android/app/benchmark/src/main/AndroidManifest.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| <manifest /> |
45 changes: 45 additions & 0 deletions
45
...ster/android/app/benchmark/src/main/java/com/example/benchmark/ExampleStartupBenchmark.kt
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * Copyright (c) Meta Platforms, Inc. and affiliates. | ||
| * | ||
| * This source code is licensed under the MIT license found in the | ||
| * LICENSE file in the root directory of this source tree. | ||
| */ | ||
|
|
||
| package com.example.benchmark | ||
|
|
||
| import androidx.benchmark.macro.StartupMode | ||
| import androidx.benchmark.macro.StartupTimingMetric | ||
| import androidx.benchmark.macro.junit4.MacrobenchmarkRule | ||
| import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import org.junit.runner.RunWith | ||
|
|
||
| /** | ||
| * This is an example startup benchmark. | ||
| * | ||
| * It navigates to the device's home screen, and launches the default activity. | ||
| * | ||
| * Before running this benchmark: | ||
| * 1) switch your app's active build variant in the Studio (affects Studio runs only) | ||
| * 2) add `<profileable android:shell="true" />` to your app's manifest, within the `<application>` | ||
| * tag | ||
| * | ||
| * Run this benchmark from Studio to see startup measurements, and captured system traces for | ||
| * investigating your app's performance. | ||
| */ | ||
| @RunWith(AndroidJUnit4::class) | ||
| class ExampleStartupBenchmark { | ||
| @get:Rule val benchmarkRule = MacrobenchmarkRule() | ||
|
|
||
| @Test | ||
| fun startup() = | ||
| benchmarkRule.measureRepeated( | ||
| packageName = "com.facebook.react.uiapp", | ||
| metrics = listOf(StartupTimingMetric()), | ||
| iterations = 10, | ||
| startupMode = StartupMode.COLD) { | ||
| pressHome() | ||
| startActivityAndWait() | ||
| } | ||
| } | ||
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
169 changes: 89 additions & 80 deletions
169
packages/rn-tester/android/app/src/main/AndroidManifest.xml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,88 +1,97 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:tools="http://schemas.android.com/tools"> | ||
|
|
||
| <uses-feature | ||
| android:name="android.software.leanback" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.touchscreen" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.location.gps" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.camera" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.software.leanback" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.touchscreen" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.location.gps" | ||
| android:required="false" /> | ||
| <uses-feature | ||
| android:name="android.hardware.camera" | ||
| android:required="false" /> | ||
|
|
||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> | ||
| <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> | ||
| <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> | ||
| <uses-permission android:name="android.permission.VIBRATE"/> | ||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/> | ||
| <uses-permission android:name="android.permission.INTERNET" /> | ||
| <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
| <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> | ||
| <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> | ||
| <uses-permission android:name="android.permission.VIBRATE" /> | ||
| <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <!-- Just to show permissions example --> | ||
| <uses-permission android:name="android.permission.CAMERA" /> | ||
| <uses-permission android:name="android.permission.READ_CALENDAR" /> | ||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS" /> | ||
|
|
||
| <!--Just to show permissions example--> | ||
| <uses-permission android:name="android.permission.CAMERA"/> | ||
| <uses-permission android:name="android.permission.READ_CALENDAR"/> | ||
| <uses-permission android:name="android.permission.POST_NOTIFICATIONS"/> | ||
| <queries> | ||
| <package android:name="com.facebook.katana" /> | ||
| <package android:name="com.facebook.lite" /> | ||
| <package android:name="com.facebook.android" /> | ||
|
|
||
| <!-- | ||
| android:icon is used to display launcher icon on mobile devices. | ||
| android:banner is used to display a rectangular banned launcher icon on Android TV devices. | ||
| --> | ||
| <application | ||
| android:name=".RNTesterApplication" | ||
| android:allowBackup="true" | ||
| android:banner="@drawable/tv_banner" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:roundIcon="@mipmap/ic_launcher_round" | ||
| android:label="@string/app_name" | ||
| android:theme="@style/AppTheme" | ||
| android:supportsRtl="true"> | ||
| <activity | ||
| android:name=".RNTesterActivity" | ||
| <intent> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
|
|
||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
|
|
||
| <data android:scheme="https" /> | ||
| </intent> | ||
| <intent> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
|
|
||
| <data android:scheme="geo" /> | ||
| </intent> | ||
| <intent> | ||
| <action android:name="android.intent.action.DIAL" /> | ||
|
|
||
| <data android:scheme="tel" /> | ||
| </intent> | ||
| </queries> | ||
|
|
||
| <application | ||
| android:name=".RNTesterApplication" | ||
| android:allowBackup="true" | ||
| android:banner="@drawable/tv_banner" | ||
| android:icon="@mipmap/ic_launcher" | ||
| android:label="@string/app_name" | ||
| android:screenOrientation="fullSensor" | ||
| android:launchMode="singleTask" | ||
| android:configChanges="orientation|screenSize|uiMode" | ||
| android:exported="true"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| <!-- Needed to properly create a launch intent when running on Android TV --> | ||
| <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> | ||
| </intent-filter> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
| <category android:name="android.intent.category.DEFAULT" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <!-- Accepts URIs that begin with "rntester://example” --> | ||
| <data android:scheme="rntester" android:host="example" /> | ||
| </intent-filter> | ||
| </activity> | ||
| <provider | ||
| android:name="com.facebook.react.modules.blob.BlobProvider" | ||
| android:authorities="@string/blob_provider_authority" | ||
| android:exported="false" | ||
| /> | ||
| </application> | ||
| <queries> | ||
| <package android:name="com.facebook.katana" /> | ||
| <package android:name="com.facebook.lite" /> | ||
| <package android:name="com.facebook.android" /> | ||
| <intent> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <data android:scheme="https" /> | ||
| </intent> | ||
| <intent> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
| <data android:scheme="geo" /> | ||
| </intent> | ||
| <intent> | ||
| <action android:name="android.intent.action.DIAL" /> | ||
| <data android:scheme="tel" /> | ||
| </intent> | ||
| </queries> | ||
| android:roundIcon="@mipmap/ic_launcher_round" | ||
| android:supportsRtl="true" | ||
| android:theme="@style/AppTheme"> | ||
| <profileable | ||
| android:shell="true" | ||
| tools:targetApi="29" /> | ||
|
|
||
| <activity | ||
| android:name=".RNTesterActivity" | ||
| android:configChanges="orientation|screenSize|uiMode" | ||
| android:exported="true" | ||
| android:label="@string/app_name" | ||
| android:launchMode="singleTask" | ||
| android:screenOrientation="fullSensor"> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.MAIN" /> | ||
|
|
||
| <category android:name="android.intent.category.LAUNCHER" /> | ||
| <!-- Needed to properly create a launch intent when running on Android TV --> | ||
| <category android:name="android.intent.category.LEANBACK_LAUNCHER" /> | ||
| </intent-filter> | ||
| <intent-filter> | ||
| <action android:name="android.intent.action.VIEW" /> | ||
|
|
||
| <category android:name="android.intent.category.DEFAULT" /> | ||
| <category android:name="android.intent.category.BROWSABLE" /> | ||
| <!-- Accepts URIs that begin with "rntester://example” --> | ||
| <data | ||
| android:host="example" | ||
| android:scheme="rntester" /> | ||
| </intent-filter> | ||
| </activity> | ||
|
|
||
| <provider | ||
| android:name="com.facebook.react.modules.blob.BlobProvider" | ||
| android:authorities="@string/blob_provider_authority" | ||
| android:exported="false" /> | ||
| </application> | ||
|
|
||
| </manifest> |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this waits for the react root view to be displayed, and not just a blank activity before react rendered?
Also are these numbers from running on emulator? They look a little bit low, hence why I am suspicious.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numbers are from running on a Pixel 8 Pro. If you run it locally you can see the RNTester home screen appearing on device 10x times