├── .buckconfig ├── .bundle └── config ├── .editorconfig ├── .eslintrc.js ├── .flowconfig ├── .gitignore ├── .prettierrc.js ├── .ruby-version ├── .watchmanconfig ├── App.js ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── __tests__ └── App-test.js ├── android ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── hermes │ ├── BUCK │ ├── build.gradle │ ├── build_defs.bzl │ ├── debug.keystore │ ├── proguard-rules.pro │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── rnbenchmark │ │ │ ├── MainActivity.java │ │ │ ├── MainApplication.java │ │ │ └── newarchitecture │ │ │ ├── MainApplicationReactNativeHost.java │ │ │ ├── components │ │ │ └── MainComponentsRegistry.java │ │ │ └── modules │ │ │ └── MainApplicationTurboModuleManagerDelegate.java │ │ ├── jni │ │ ├── Android.mk │ │ ├── MainApplicationModuleProvider.cpp │ │ ├── MainApplicationModuleProvider.h │ │ ├── MainApplicationTurboModuleManagerDelegate.cpp │ │ ├── MainApplicationTurboModuleManagerDelegate.h │ │ ├── MainComponentsRegistry.cpp │ │ ├── MainComponentsRegistry.h │ │ └── OnLoad.cpp │ │ └── res │ │ ├── drawable-mdpi │ │ └── node_modules_reactnative_libraries_newappscreen_components_logo.png │ │ ├── drawable │ │ └── rn_edit_text_material.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── jsc │ ├── BUCK │ ├── build.gradle │ ├── build_defs.bzl │ ├── debug.keystore │ ├── proguard-rules.pro │ └── src │ │ ├── debug │ │ └── AndroidManifest.xml │ │ └── main │ │ ├── AndroidManifest.xml │ │ ├── java │ │ └── com │ │ │ └── rnbenchmark │ │ │ ├── MainActivity.java │ │ │ ├── MainApplication.java │ │ │ └── newarchitecture │ │ │ ├── MainApplicationReactNativeHost.java │ │ │ ├── components │ │ │ └── MainComponentsRegistry.java │ │ │ └── modules │ │ │ └── MainApplicationTurboModuleManagerDelegate.java │ │ ├── jni │ │ ├── Android.mk │ │ ├── MainApplicationModuleProvider.cpp │ │ ├── MainApplicationModuleProvider.h │ │ ├── MainApplicationTurboModuleManagerDelegate.cpp │ │ ├── MainApplicationTurboModuleManagerDelegate.h │ │ ├── MainComponentsRegistry.cpp │ │ ├── MainComponentsRegistry.h │ │ └── OnLoad.cpp │ │ └── res │ │ ├── drawable-mdpi │ │ └── node_modules_reactnative_libraries_newappscreen_components_logo.png │ │ ├── drawable │ │ └── rn_edit_text_material.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── strings.xml │ │ └── styles.xml ├── settings.gradle └── v8 │ ├── BUCK │ ├── build.gradle │ ├── build_defs.bzl │ ├── debug.keystore │ ├── proguard-rules.pro │ └── src │ ├── debug │ └── AndroidManifest.xml │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── rnbenchmark │ │ ├── MainActivity.java │ │ ├── MainApplication.java │ │ └── newarchitecture │ │ ├── MainApplicationReactNativeHost.java │ │ ├── components │ │ └── MainComponentsRegistry.java │ │ └── modules │ │ └── MainApplicationTurboModuleManagerDelegate.java │ ├── jni │ ├── Android.mk │ ├── MainApplicationModuleProvider.cpp │ ├── MainApplicationModuleProvider.h │ ├── MainApplicationTurboModuleManagerDelegate.cpp │ ├── MainApplicationTurboModuleManagerDelegate.h │ ├── MainComponentsRegistry.cpp │ ├── MainComponentsRegistry.h │ └── OnLoad.cpp │ └── res │ ├── drawable-mdpi │ └── node_modules_reactnative_libraries_newappscreen_components_logo.png │ ├── drawable │ └── rn_edit_text_material.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ └── values │ ├── strings.xml │ └── styles.xml ├── app.json ├── babel.config.js ├── index.js ├── js_dists.py ├── lib ├── __init__.py ├── colorful.py ├── logger.py ├── section.py ├── tools.py └── types.py ├── metro.config.js ├── package.json ├── react-native.config.js ├── src ├── ReactRender │ ├── RenderComponentMemory.js │ └── RenderComponentThroughput.js └── TTI │ ├── TTIView.js │ └── data.json ├── start.py ├── website ├── .eslintrc.json ├── .gitignore ├── .prettierrc ├── README.md ├── components │ └── Chart.tsx ├── env-config.js ├── next-env.d.ts ├── next.config.js ├── out │ ├── 404.html │ ├── _next │ │ └── static │ │ │ ├── chunks │ │ │ ├── 333-7d5bcd5502c82377.js │ │ │ ├── 36bcf0ca-38c7a396cae02552.js │ │ │ ├── framework-00b57966872fc495.js │ │ │ ├── main-f4ae3437c92c1efc.js │ │ │ ├── pages │ │ │ │ ├── _app-85d7488a393e293e.js │ │ │ │ ├── _error-1995526792b513b2.js │ │ │ │ └── index-b051f3a4587db0bf.js │ │ │ ├── polyfills-5cd94c89d3acac5f.js │ │ │ └── webpack-3c5894a45e827ae9.js │ │ │ ├── css │ │ │ ├── 27d177a30947857b.css │ │ │ └── dad84d14e16a7e3d.css │ │ │ └── fhXGm-tGR2o6BukQJOeI8 │ │ │ ├── _buildManifest.js │ │ │ ├── _middlewareManifest.js │ │ │ └── _ssgManifest.js │ ├── data.json │ └── index.html ├── package.json ├── pages │ ├── _app.tsx │ └── index.tsx ├── public │ └── data.json ├── styles │ ├── Chart.module.css │ ├── Home.module.css │ └── globals.css ├── tsconfig.json ├── types │ └── index.ts └── yarn.lock └── yarn.lock /.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Windows files 2 | [*.bat] 3 | end_of_line = crlf 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; Flow doesn't support platforms 12 | .*/Libraries/Utilities/LoadingView.js 13 | 14 | .*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$ 15 | 16 | [untyped] 17 | .*/node_modules/@react-native-community/cli/.*/.* 18 | 19 | [include] 20 | 21 | [libs] 22 | node_modules/react-native/interface.js 23 | node_modules/react-native/flow/ 24 | 25 | [options] 26 | emoji=true 27 | 28 | exact_by_default=true 29 | 30 | format.bracket_spacing=false 31 | 32 | module.file_ext=.js 33 | module.file_ext=.json 34 | module.file_ext=.ios.js 35 | 36 | munge_underscores=true 37 | 38 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 39 | module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 40 | 41 | suppress_type=$FlowIssue 42 | suppress_type=$FlowFixMe 43 | suppress_type=$FlowFixMeProps 44 | suppress_type=$FlowFixMeState 45 | 46 | [lints] 47 | sketchy-null-number=warn 48 | sketchy-null-mixed=warn 49 | sketchy-number=warn 50 | untyped-type-import=warn 51 | nonstrict-import=warn 52 | deprecated-type=warn 53 | unsafe-getters-setters=warn 54 | unnecessary-invariant=warn 55 | signature-verification-failure=warn 56 | 57 | [strict] 58 | deprecated-type 59 | nonstrict-import 60 | sketchy-null 61 | unclear-type 62 | unsafe-getters-setters 63 | untyped-import 64 | untyped-type-import 65 | 66 | [version] 67 | ^0.170.0 68 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | 24 | # Android/IntelliJ 25 | # 26 | build/ 27 | .idea 28 | .gradle 29 | local.properties 30 | *.iml 31 | *.hprof 32 | 33 | # node.js 34 | # 35 | node_modules/ 36 | npm-debug.log 37 | yarn-error.log 38 | 39 | # BUCK 40 | buck-out/ 41 | \.buckd/ 42 | *.keystore 43 | !debug.keystore 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://docs.fastlane.tools/best-practices/source-control/ 51 | 52 | */fastlane/report.xml 53 | */fastlane/Preview.html 54 | */fastlane/screenshots 55 | 56 | # Bundle artifact 57 | *.jsbundle 58 | 59 | # Ruby / CocoaPods 60 | /ios/Pods/ 61 | /vendor/bundle/ 62 | 63 | # JS dist 64 | js_dist/ 65 | 66 | # Python bytecode cache 67 | *.pyc 68 | __pycache__ 69 | -------------------------------------------------------------------------------- /.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: true, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.4 2 | -------------------------------------------------------------------------------- /.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import React, { useEffect, useState } from 'react'; 6 | import { View, Text, Linking, StyleSheet } from 'react-native'; 7 | import URL from 'url-parse'; 8 | 9 | const ROUTES = { 10 | '/RenderComponentThroughput': 11 | require('./src/ReactRender/RenderComponentThroughput').default, 12 | '/RenderComponentMemory': require('./src/ReactRender/RenderComponentMemory') 13 | .default, 14 | '/TTI': require('./src/TTI/TTIView').default, 15 | }; 16 | 17 | const NotFoundView = () => ( 18 | 19 | View not found 20 | 21 | ); 22 | 23 | function App() { 24 | const [route, setRoute] = useState(null); 25 | useEffect(() => { 26 | async function setupInitialRoute() { 27 | const initialUrl = await Linking.getInitialURL(); 28 | if (initialUrl && initialUrl.startsWith('rnbench://')) { 29 | const url = new URL(initialUrl, '', true); 30 | setRoute(url); 31 | } 32 | } 33 | 34 | setupInitialRoute(); 35 | }, []); 36 | 37 | return ( 38 | 39 | {route != null && ROUTES[route.pathname] != null ? ( 40 | React.createElement(ROUTES[route.pathname], route.query) 41 | ) : ( 42 | 43 | )} 44 | 45 | ); 46 | } 47 | 48 | const styles = StyleSheet.create({ 49 | container: { 50 | flex: 1, 51 | }, 52 | notFoundView: { 53 | flex: 1, 54 | backgroundColor: 'rgb(192, 186, 48)', 55 | flexDirection: 'column', 56 | justifyContent: 'center', 57 | }, 58 | notFoundText: { 59 | color: 'rgb(255, 255, 255)', 60 | fontSize: 32, 61 | textAlign: 'center', 62 | }, 63 | }); 64 | 65 | export default App; 66 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby '2.7.4' 5 | 6 | gem 'cocoapods', '~> 1.11', '>= 1.11.2' 7 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (3.0.5) 5 | rexml 6 | activesupport (6.1.5) 7 | concurrent-ruby (~> 1.0, >= 1.0.2) 8 | i18n (>= 1.6, < 2) 9 | minitest (>= 5.1) 10 | tzinfo (~> 2.0) 11 | zeitwerk (~> 2.3) 12 | addressable (2.8.0) 13 | public_suffix (>= 2.0.2, < 5.0) 14 | algoliasearch (1.27.5) 15 | httpclient (~> 2.8, >= 2.8.3) 16 | json (>= 1.5.1) 17 | atomos (0.1.3) 18 | claide (1.1.0) 19 | cocoapods (1.11.3) 20 | addressable (~> 2.8) 21 | claide (>= 1.0.2, < 2.0) 22 | cocoapods-core (= 1.11.3) 23 | cocoapods-deintegrate (>= 1.0.3, < 2.0) 24 | cocoapods-downloader (>= 1.4.0, < 2.0) 25 | cocoapods-plugins (>= 1.0.0, < 2.0) 26 | cocoapods-search (>= 1.0.0, < 2.0) 27 | cocoapods-trunk (>= 1.4.0, < 2.0) 28 | cocoapods-try (>= 1.1.0, < 2.0) 29 | colored2 (~> 3.1) 30 | escape (~> 0.0.4) 31 | fourflusher (>= 2.3.0, < 3.0) 32 | gh_inspector (~> 1.0) 33 | molinillo (~> 0.8.0) 34 | nap (~> 1.0) 35 | ruby-macho (>= 1.0, < 3.0) 36 | xcodeproj (>= 1.21.0, < 2.0) 37 | cocoapods-core (1.11.3) 38 | activesupport (>= 5.0, < 7) 39 | addressable (~> 2.8) 40 | algoliasearch (~> 1.0) 41 | concurrent-ruby (~> 1.1) 42 | fuzzy_match (~> 2.0.4) 43 | nap (~> 1.0) 44 | netrc (~> 0.11) 45 | public_suffix (~> 4.0) 46 | typhoeus (~> 1.0) 47 | cocoapods-deintegrate (1.0.5) 48 | cocoapods-downloader (1.6.3) 49 | cocoapods-plugins (1.0.0) 50 | nap 51 | cocoapods-search (1.0.1) 52 | cocoapods-trunk (1.6.0) 53 | nap (>= 0.8, < 2.0) 54 | netrc (~> 0.11) 55 | cocoapods-try (1.2.0) 56 | colored2 (3.1.2) 57 | concurrent-ruby (1.1.10) 58 | escape (0.0.4) 59 | ethon (0.15.0) 60 | ffi (>= 1.15.0) 61 | ffi (1.15.5) 62 | fourflusher (2.3.1) 63 | fuzzy_match (2.0.4) 64 | gh_inspector (1.1.3) 65 | httpclient (2.8.3) 66 | i18n (1.10.0) 67 | concurrent-ruby (~> 1.0) 68 | json (2.6.1) 69 | minitest (5.15.0) 70 | molinillo (0.8.0) 71 | nanaimo (0.3.0) 72 | nap (1.1.0) 73 | netrc (0.11.0) 74 | public_suffix (4.0.7) 75 | rexml (3.2.5) 76 | ruby-macho (2.5.1) 77 | typhoeus (1.4.0) 78 | ethon (>= 0.9.0) 79 | tzinfo (2.0.4) 80 | concurrent-ruby (~> 1.0) 81 | xcodeproj (1.21.0) 82 | CFPropertyList (>= 2.3.3, < 4.0) 83 | atomos (~> 0.1.3) 84 | claide (>= 1.0.2, < 2.0) 85 | colored2 (~> 3.1) 86 | nanaimo (~> 0.3.0) 87 | rexml (~> 3.2.4) 88 | zeitwerk (2.5.4) 89 | 90 | PLATFORMS 91 | ruby 92 | 93 | DEPENDENCIES 94 | cocoapods (~> 1.11, >= 1.11.2) 95 | 96 | RUBY VERSION 97 | ruby 2.7.4p191 98 | 99 | BUNDLED WITH 100 | 2.2.27 101 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Kudo Chien 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript Engine Benchmark for React Native 2 | 3 | ## Benchmark Results 4 | 5 | [RN 0.62.2, JSC 250230, V8 8.0, Hermes 0.4.1](https://docs.google.com/spreadsheets/d/1XB6fuk-NYZbCDikxQOAJemE-P8cfbsfdXivTeVwcwIk/edit?usp=sharing) 6 | 7 | [RN 0.60.3, JSC 245459, V8 7.5.1, Hermes 0.1.0](https://docs.google.com/spreadsheets/d/1uce3WZ9IaAEUu6Owj3eXEuZb25PDi6ZcgUVV2i500S0/edit#gid=1258377944) 8 | 9 | These benchmarks ran on Samsung Galaxy Note 5 10 | 11 | ## Benchmarks 12 | 13 | ### React Rendering 14 | 15 | - RenderComponentThroughput 16 | 17 | The series of test cases aim to measure how many React component could be rendered within some intervals. 18 | 19 | - RenderComponentThroughput 10s 20 | - RenderComponentThroughput 60s 21 | - RenderComponentThroughput 180s 22 | 23 | The reason that have different interval is that to assume JIT will start to work after longer repetitive executions. 24 | 25 | **Higher result is better** 26 | 27 | ### TTI (Time-To-Interaction) 28 | 29 | The series of test cases aim to measure how long JS engine parse and evaluate the scripts. 30 | TTI time is from the `content_appear_view_time - before_start_ReactInstanceManager_time`. 31 | In different test cases, we try to generate different size of JS bundle and compare if size matters. 32 | 33 | - TTI ~3 MiB bundle 34 | - TTI ~10 MiB bundle 35 | - TTI ~15 MiB bundle 36 | 37 | ### APK Size 38 | 39 | Simply the comparion of library binary size and final APK size. 40 | 41 | ## How to Run the Benchmark 42 | 43 | Prerequisites: 44 | 45 | - macOS 10.14 (Other macOS versions or Linux might be supported, but I don't verify that) 46 | - Python 3 47 | - Node 8+ 48 | 49 | Simply to run 50 | 51 | ```sh 52 | python start.py -a 53 | ``` 54 | 55 | ## Disclaimer 56 | 57 | This project is specific to measure JS engine performance for React Native. It is not designated to do generic JS engine comparison. 58 | 59 | For example, on React Native Android, we don't enable all JIT tiers on JavaScriptCore. On V8, I am currently trying to use the JIT-less mode. What I am trying to do is balancing between good enough performance, low memory usage, and small binary size. That is why to disable JIT sometimes. 60 | 61 | -------------------------------------------------------------------------------- /__tests__/App-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import 'react-native'; 6 | import React from 'react'; 7 | import App from '../App'; 8 | 9 | // Note: test renderer must be required after react-native. 10 | import renderer from 'react-test-renderer'; 11 | 12 | it('renders correctly', () => { 13 | renderer.create(); 14 | }); 15 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 4 | 5 | buildscript { 6 | ext { 7 | buildToolsVersion = "31.0.0" 8 | minSdkVersion = 21 9 | compileSdkVersion = 31 10 | targetSdkVersion = 31 11 | 12 | if (System.properties['os.arch'] == "aarch64") { 13 | // For M1 Users we need to use the NDK 24 which added support for aarch64 14 | ndkVersion = "24.0.8215888" 15 | } else if (Os.isFamily(Os.FAMILY_WINDOWS)) { 16 | // For Android Users, we need to use NDK 23, otherwise the build will 17 | // fail due to paths longer than the OS limit 18 | ndkVersion = "23.1.7779620" 19 | } else { 20 | // Otherwise we default to the side-by-side NDK version from AGP. 21 | ndkVersion = "21.4.7075529" 22 | } 23 | } 24 | repositories { 25 | google() 26 | mavenCentral() 27 | } 28 | dependencies { 29 | classpath("com.android.tools.build:gradle:7.0.4") 30 | classpath("com.facebook.react:react-native-gradle-plugin") 31 | classpath("de.undercouch:gradle-download-task:4.1.2") 32 | // NOTE: Do not place your application dependencies here; they belong 33 | // in the individual module build.gradle files 34 | } 35 | } 36 | 37 | allprojects { 38 | repositories { 39 | maven { 40 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 41 | url("$rootDir/../node_modules/react-native/android") 42 | } 43 | maven { 44 | // Android JSC is installed from npm 45 | url("$rootDir/../node_modules/jsc-android/dist") 46 | } 47 | mavenCentral { 48 | // We don't want to fetch react-native from Maven Central as there are 49 | // older versions over there. 50 | content { 51 | excludeGroup "com.facebook.react" 52 | } 53 | } 54 | google() 55 | maven { url 'https://www.jitpack.io' } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.125.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | v8.appProject=v8 43 | -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega 90 | -------------------------------------------------------------------------------- /android/hermes/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.rnbenchmark", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.rnbenchmark", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /android/hermes/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | repositories { 4 | maven { 5 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 6 | url("$rootDir/../node_modules/react-native/android") 7 | content { 8 | includeGroup "com.facebook.react" 9 | } 10 | } 11 | } 12 | 13 | import com.android.build.OutputFile 14 | 15 | /** 16 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 17 | * and bundleReleaseJsAndAssets). 18 | * These basically call `react-native bundle` with the correct arguments during the Android build 19 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 20 | * bundle directly from the development server. Below you can see all the possible configurations 21 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 22 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 23 | * 24 | * project.ext.react = [ 25 | * // the name of the generated asset file containing your JS bundle 26 | * bundleAssetName: "index.android.bundle", 27 | * 28 | * // the entry file for bundle generation. If none specified and 29 | * // "index.android.js" exists, it will be used. Otherwise "index.js" is 30 | * // default. Can be overridden with ENTRY_FILE environment variable. 31 | * entryFile: "index.android.js", 32 | * 33 | * // https://reactnative.dev/docs/performance#enable-the-ram-format 34 | * bundleCommand: "ram-bundle", 35 | * 36 | * // whether to bundle JS and assets in debug mode 37 | * bundleInDebug: false, 38 | * 39 | * // whether to bundle JS and assets in release mode 40 | * bundleInRelease: true, 41 | * 42 | * // whether to bundle JS and assets in another build variant (if configured). 43 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 44 | * // The configuration property can be in the following formats 45 | * // 'bundleIn${productFlavor}${buildType}' 46 | * // 'bundleIn${buildType}' 47 | * // bundleInFreeDebug: true, 48 | * // bundleInPaidRelease: true, 49 | * // bundleInBeta: true, 50 | * 51 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 52 | * // for example: to disable dev mode in the staging build type (if configured) 53 | * devDisabledInStaging: true, 54 | * // The configuration property can be in the following formats 55 | * // 'devDisabledIn${productFlavor}${buildType}' 56 | * // 'devDisabledIn${buildType}' 57 | * 58 | * // the root of your project, i.e. where "package.json" lives 59 | * root: "../../", 60 | * 61 | * // where to put the JS bundle asset in debug mode 62 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 63 | * 64 | * // where to put the JS bundle asset in release mode 65 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 66 | * 67 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 68 | * // require('./image.png')), in debug mode 69 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 70 | * 71 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 72 | * // require('./image.png')), in release mode 73 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 74 | * 75 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 76 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 77 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 78 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 79 | * // for example, you might want to remove it from here. 80 | * inputExcludes: ["android/**", "ios/**"], 81 | * 82 | * // override which node gets called and with what additional arguments 83 | * nodeExecutableAndArgs: ["node"], 84 | * 85 | * // supply additional arguments to the packager 86 | * extraPackagerArgs: [] 87 | * ] 88 | */ 89 | 90 | project.ext.react = [ 91 | entryFile: "index.js", 92 | enableHermes: true, // clean and rebuild if changing 93 | ] 94 | 95 | apply from: "../../node_modules/react-native/react.gradle" 96 | 97 | /** 98 | * Set this to true to create two separate APKs instead of one: 99 | * - An APK that only works on ARM devices 100 | * - An APK that only works on x86 devices 101 | * The advantage is the size of the APK is reduced by about 4MB. 102 | * Upload all the APKs to the Play Store and people will download 103 | * the correct one based on the CPU architecture of their device. 104 | */ 105 | def enableSeparateBuildPerCPUArchitecture = project.findProperty('ABI_BASED_APK') == 'true' 106 | 107 | /** 108 | * Run Proguard to shrink the Java bytecode in release builds. 109 | */ 110 | def enableProguardInReleaseBuilds = false 111 | 112 | /** 113 | * The preferred build flavor of JavaScriptCore. 114 | * 115 | * For example, to use the international variant, you can use: 116 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 117 | * 118 | * The international variant includes ICU i18n library and necessary data 119 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 120 | * give correct results when using with locales other than en-US. Note that 121 | * this variant is about 6MiB larger per architecture than default. 122 | */ 123 | def jscFlavor = 'org.webkit:android-jsc:+' 124 | 125 | /** 126 | * Whether to enable the Hermes VM. 127 | * 128 | * This should be set on project.ext.react and that value will be read here. If it is not set 129 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 130 | * and the benefits of using Hermes will therefore be sharply reduced. 131 | */ 132 | def enableHermes = project.ext.react.get("enableHermes", false); 133 | 134 | /** 135 | * Architectures to build native code for. 136 | */ 137 | def reactNativeArchitectures() { 138 | def value = project.getProperties().get("reactNativeArchitectures") 139 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 140 | } 141 | 142 | android { 143 | ndkVersion rootProject.ext.ndkVersion 144 | 145 | compileSdkVersion rootProject.ext.compileSdkVersion 146 | 147 | defaultConfig { 148 | applicationId "com.rnbenchmark.hermes" 149 | minSdkVersion rootProject.ext.minSdkVersion 150 | targetSdkVersion rootProject.ext.targetSdkVersion 151 | versionCode 1 152 | versionName "1.0" 153 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 154 | 155 | if (isNewArchitectureEnabled()) { 156 | // We configure the NDK build only if you decide to opt-in for the New Architecture. 157 | externalNativeBuild { 158 | ndkBuild { 159 | arguments "APP_PLATFORM=android-21", 160 | "APP_STL=c++_shared", 161 | "NDK_TOOLCHAIN_VERSION=clang", 162 | "GENERATED_SRC_DIR=$buildDir/generated/source", 163 | "PROJECT_BUILD_DIR=$buildDir", 164 | "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", 165 | "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build" 166 | cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" 167 | cppFlags "-std=c++17" 168 | // Make sure this target name is the same you specify inside the 169 | // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable. 170 | targets "rnbenchmark_appmodules" 171 | 172 | // Fix for windows limit on number of character in file paths and in command lines 173 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 174 | arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx", 175 | "NDK_APP_SHORT_COMMANDS=true" 176 | } 177 | } 178 | } 179 | if (!enableSeparateBuildPerCPUArchitecture) { 180 | ndk { 181 | abiFilters (*reactNativeArchitectures()) 182 | } 183 | } 184 | } 185 | } 186 | 187 | if (isNewArchitectureEnabled()) { 188 | // We configure the NDK build only if you decide to opt-in for the New Architecture. 189 | externalNativeBuild { 190 | ndkBuild { 191 | path "$projectDir/src/main/jni/Android.mk" 192 | } 193 | } 194 | def reactAndroidProjectDir = project(':ReactAndroid').projectDir 195 | def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { 196 | dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") 197 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") 198 | into("$buildDir/react-ndk/exported") 199 | } 200 | def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { 201 | dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") 202 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") 203 | into("$buildDir/react-ndk/exported") 204 | } 205 | afterEvaluate { 206 | // If you wish to add a custom TurboModule or component locally, 207 | // you should uncomment this line. 208 | // preBuild.dependsOn("generateCodegenArtifactsFromSchema") 209 | preDebugBuild.dependsOn(packageReactNdkDebugLibs) 210 | preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) 211 | 212 | // Due to a bug inside AGP, we have to explicitly set a dependency 213 | // between configureNdkBuild* tasks and the preBuild tasks. 214 | // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 215 | configureNdkBuildRelease.dependsOn(preReleaseBuild) 216 | configureNdkBuildDebug.dependsOn(preDebugBuild) 217 | reactNativeArchitectures().each { architecture -> 218 | tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { 219 | dependsOn("preDebugBuild") 220 | } 221 | tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { 222 | dependsOn("preReleaseBuild") 223 | } 224 | } 225 | } 226 | } 227 | 228 | splits { 229 | abi { 230 | reset() 231 | enable enableSeparateBuildPerCPUArchitecture 232 | universalApk false // If true, also generate a universal APK 233 | include (*reactNativeArchitectures()) 234 | } 235 | } 236 | signingConfigs { 237 | debug { 238 | storeFile file('debug.keystore') 239 | storePassword 'android' 240 | keyAlias 'androiddebugkey' 241 | keyPassword 'android' 242 | } 243 | } 244 | buildTypes { 245 | debug { 246 | signingConfig signingConfigs.debug 247 | } 248 | release { 249 | // Caution! In production, you need to generate your own keystore file. 250 | // see https://reactnative.dev/docs/signed-apk-android. 251 | signingConfig signingConfigs.debug 252 | minifyEnabled enableProguardInReleaseBuilds 253 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 254 | } 255 | } 256 | 257 | // applicationVariants are e.g. debug, release 258 | applicationVariants.all { variant -> 259 | variant.outputs.each { output -> 260 | // For each separate APK per architecture, set a unique version code as described here: 261 | // https://developer.android.com/studio/build/configure-apk-splits.html 262 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 263 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 264 | def abi = output.getFilter(OutputFile.ABI) 265 | if (abi != null) { // null for the universal-debug, universal-release variants 266 | output.versionCodeOverride = 267 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 268 | } 269 | 270 | } 271 | } 272 | } 273 | 274 | dependencies { 275 | implementation fileTree(dir: "libs", include: ["*.jar"]) 276 | //noinspection GradleDynamicVersion 277 | implementation "com.facebook.react:react-native:+" // From node_modules 278 | 279 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 280 | 281 | if (enableHermes) { 282 | def hermesPath = project.findProperty("MAVEN_REPO") ?: "../../node_modules/hermes-engine/android"; 283 | debugImplementation files(hermesPath + "/hermes-debug.aar") 284 | releaseImplementation files(hermesPath + "/hermes-release.aar") 285 | } else { 286 | implementation jscFlavor 287 | } 288 | } 289 | 290 | if (isNewArchitectureEnabled()) { 291 | // If new architecture is enabled, we let you build RN from source 292 | // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. 293 | // This will be applied to all the imported transtitive dependency. 294 | configurations.all { 295 | resolutionStrategy.dependencySubstitution { 296 | substitute(module("com.facebook.react:react-native")) 297 | .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source") 298 | } 299 | } 300 | } 301 | 302 | // Run this once to be able to run the application with BUCK 303 | // puts all compile dependencies into folder libs for BUCK to use 304 | task copyDownloadableDepsToLibs(type: Copy) { 305 | from configurations.implementation 306 | into 'libs' 307 | } 308 | 309 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 310 | 311 | def isNewArchitectureEnabled() { 312 | // To opt-in for the New Architecture, you can either: 313 | // - Set `newArchEnabled` to true inside the `gradle.properties` file 314 | // - Invoke gradle with `-newArchEnabled=true` 315 | // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` 316 | return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" 317 | } 318 | -------------------------------------------------------------------------------- /android/hermes/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /android/hermes/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/debug.keystore -------------------------------------------------------------------------------- /android/hermes/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /android/hermes/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /android/hermes/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/hermes/src/main/java/com/rnbenchmark/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.ReactRootView; 6 | 7 | public class MainActivity extends ReactActivity { 8 | 9 | /** 10 | * Returns the name of the main component registered from JavaScript. This is used to schedule 11 | * rendering of the component. 12 | */ 13 | @Override 14 | protected String getMainComponentName() { 15 | return "RNBenchmark"; 16 | } 17 | 18 | /** 19 | * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and 20 | * you can specify the rendered you wish to use (Fabric or the older renderer). 21 | */ 22 | @Override 23 | protected ReactActivityDelegate createReactActivityDelegate() { 24 | return new MainActivityDelegate(this, getMainComponentName()); 25 | } 26 | 27 | public static class MainActivityDelegate extends ReactActivityDelegate { 28 | public MainActivityDelegate(ReactActivity activity, String mainComponentName) { 29 | super(activity, mainComponentName); 30 | } 31 | 32 | @Override 33 | protected ReactRootView createRootView() { 34 | ReactRootView reactRootView = new ReactRootView(getContext()); 35 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 36 | reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); 37 | return reactRootView; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android/hermes/src/main/java/com/rnbenchmark/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.facebook.react.PackageList; 8 | import com.facebook.react.ReactApplication; 9 | import com.facebook.react.ReactNativeHost; 10 | import com.facebook.react.ReactInstanceManager; 11 | import com.facebook.react.ReactPackage; 12 | import com.facebook.react.config.ReactFeatureFlags; 13 | import com.facebook.react.bridge.ReactMarker; 14 | import com.facebook.react.bridge.ReactMarkerConstants; 15 | import com.facebook.soloader.SoLoader; 16 | import com.rnbenchmark.newarchitecture.MainApplicationReactNativeHost; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | public class MainApplication extends Application implements 24 | ReactApplication, 25 | ReactMarker.MarkerListener { 26 | 27 | private long mTTIStartTime; 28 | private long mTTIEndTime; 29 | 30 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 31 | @Override 32 | public boolean getUseDeveloperSupport() { 33 | return BuildConfig.DEBUG; 34 | } 35 | 36 | @Override 37 | protected List getPackages() { 38 | @SuppressWarnings("UnnecessaryLocalVariable") 39 | List packages = new PackageList(this).getPackages(); 40 | // Packages that cannot be autolinked yet can be added manually here, for example: 41 | // packages.add(new MyReactNativePackage()); 42 | return packages; 43 | } 44 | 45 | @Override 46 | protected String getJSMainModuleName() { 47 | return "index"; 48 | } 49 | }; 50 | 51 | private final ReactNativeHost mNewArchitectureNativeHost = 52 | new MainApplicationReactNativeHost(this); 53 | 54 | @Override 55 | public ReactNativeHost getReactNativeHost() { 56 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 57 | return mNewArchitectureNativeHost; 58 | } else { 59 | return mReactNativeHost; 60 | } 61 | } 62 | 63 | @Override 64 | public void onCreate() { 65 | super.onCreate(); 66 | ReactMarker.addListener(this); 67 | // If you opted-in for the New Architecture, we enable the TurboModule system 68 | ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 69 | SoLoader.init(this, /* native exopackage */ false); 70 | // initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 71 | } 72 | 73 | /** 74 | * Loads Flipper in React Native templates. 75 | * 76 | * @param context 77 | */ 78 | private static void initializeFlipper( 79 | Context context, ReactInstanceManager reactInstanceManager) { 80 | if (BuildConfig.DEBUG) { 81 | try { 82 | /* 83 | We use reflection here to pick up the class that initializes Flipper, 84 | since Flipper library is not available in release mode 85 | */ 86 | Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); 87 | aClass 88 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 89 | .invoke(null, context, reactInstanceManager); 90 | } catch (ClassNotFoundException e) { 91 | e.printStackTrace(); 92 | } catch (NoSuchMethodException e) { 93 | e.printStackTrace(); 94 | } catch (IllegalAccessException e) { 95 | e.printStackTrace(); 96 | } catch (InvocationTargetException e) { 97 | e.printStackTrace(); 98 | } 99 | } 100 | } 101 | 102 | @Override 103 | public void onTerminate() { 104 | ReactMarker.removeListener(this); 105 | super.onTerminate(); 106 | } 107 | 108 | // 109 | // ReactMarker.MarkerListener implementations 110 | // 111 | @Override 112 | public void logMarker(ReactMarkerConstants name, @Nullable String tag, int instanceKey) { 113 | if (name == ReactMarkerConstants.GET_REACT_INSTANCE_MANAGER_START) { 114 | mTTIStartTime = System.currentTimeMillis(); 115 | } else if (name == ReactMarkerConstants.CONTENT_APPEARED) { 116 | mTTIEndTime = System.currentTimeMillis(); 117 | Log.i("MeasureTTI", "TTI=" + (mTTIEndTime - mTTIStartTime)); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /android/hermes/src/main/java/com/rnbenchmark/newarchitecture/MainApplicationReactNativeHost.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture; 2 | 3 | import android.app.Application; 4 | import androidx.annotation.NonNull; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactInstanceManager; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 10 | import com.facebook.react.bridge.JSIModulePackage; 11 | import com.facebook.react.bridge.JSIModuleProvider; 12 | import com.facebook.react.bridge.JSIModuleSpec; 13 | import com.facebook.react.bridge.JSIModuleType; 14 | import com.facebook.react.bridge.JavaScriptContextHolder; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.UIManager; 17 | import com.facebook.react.fabric.ComponentFactory; 18 | import com.facebook.react.fabric.CoreComponentsRegistry; 19 | import com.facebook.react.fabric.EmptyReactNativeConfig; 20 | import com.facebook.react.fabric.FabricJSIModuleProvider; 21 | import com.facebook.react.uimanager.ViewManagerRegistry; 22 | import com.rnbenchmark.BuildConfig; 23 | import com.rnbenchmark.newarchitecture.components.MainComponentsRegistry; 24 | import com.rnbenchmark.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both 30 | * TurboModule delegates and the Fabric Renderer. 31 | * 32 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 33 | * `newArchEnabled` property). Is ignored otherwise. 34 | */ 35 | public class MainApplicationReactNativeHost extends ReactNativeHost { 36 | public MainApplicationReactNativeHost(Application application) { 37 | super(application); 38 | } 39 | 40 | @Override 41 | public boolean getUseDeveloperSupport() { 42 | return BuildConfig.DEBUG; 43 | } 44 | 45 | @Override 46 | protected List getPackages() { 47 | List packages = new PackageList(this).getPackages(); 48 | // Packages that cannot be autolinked yet can be added manually here, for example: 49 | // packages.add(new MyReactNativePackage()); 50 | // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: 51 | // packages.add(new TurboReactPackage() { ... }); 52 | // If you have custom Fabric Components, their ViewManagers should also be loaded here 53 | // inside a ReactPackage. 54 | return packages; 55 | } 56 | 57 | @Override 58 | protected String getJSMainModuleName() { 59 | return "index"; 60 | } 61 | 62 | @NonNull 63 | @Override 64 | protected ReactPackageTurboModuleManagerDelegate.Builder 65 | getReactPackageTurboModuleManagerDelegateBuilder() { 66 | // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary 67 | // for the new architecture and to use TurboModules correctly. 68 | return new MainApplicationTurboModuleManagerDelegate.Builder(); 69 | } 70 | 71 | @Override 72 | protected JSIModulePackage getJSIModulePackage() { 73 | return new JSIModulePackage() { 74 | @Override 75 | public List getJSIModules( 76 | final ReactApplicationContext reactApplicationContext, 77 | final JavaScriptContextHolder jsContext) { 78 | final List specs = new ArrayList<>(); 79 | 80 | // Here we provide a new JSIModuleSpec that will be responsible of providing the 81 | // custom Fabric Components. 82 | specs.add( 83 | new JSIModuleSpec() { 84 | @Override 85 | public JSIModuleType getJSIModuleType() { 86 | return JSIModuleType.UIManager; 87 | } 88 | 89 | @Override 90 | public JSIModuleProvider getJSIModuleProvider() { 91 | final ComponentFactory componentFactory = new ComponentFactory(); 92 | CoreComponentsRegistry.register(componentFactory); 93 | 94 | // Here we register a Components Registry. 95 | // The one that is generated with the template contains no components 96 | // and just provides you the one from React Native core. 97 | MainComponentsRegistry.register(componentFactory); 98 | 99 | final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); 100 | 101 | ViewManagerRegistry viewManagerRegistry = 102 | new ViewManagerRegistry( 103 | reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); 104 | 105 | return new FabricJSIModuleProvider( 106 | reactApplicationContext, 107 | componentFactory, 108 | new EmptyReactNativeConfig(), 109 | viewManagerRegistry); 110 | } 111 | }); 112 | return specs; 113 | } 114 | }; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /android/hermes/src/main/java/com/rnbenchmark/newarchitecture/components/MainComponentsRegistry.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.components; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.proguard.annotations.DoNotStrip; 5 | import com.facebook.react.fabric.ComponentFactory; 6 | import com.facebook.soloader.SoLoader; 7 | 8 | /** 9 | * Class responsible to load the custom Fabric Components. This class has native methods and needs a 10 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 11 | * folder for you). 12 | * 13 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 14 | * `newArchEnabled` property). Is ignored otherwise. 15 | */ 16 | @DoNotStrip 17 | public class MainComponentsRegistry { 18 | static { 19 | SoLoader.loadLibrary("fabricjni"); 20 | } 21 | 22 | @DoNotStrip private final HybridData mHybridData; 23 | 24 | @DoNotStrip 25 | private native HybridData initHybrid(ComponentFactory componentFactory); 26 | 27 | @DoNotStrip 28 | private MainComponentsRegistry(ComponentFactory componentFactory) { 29 | mHybridData = initHybrid(componentFactory); 30 | } 31 | 32 | @DoNotStrip 33 | public static MainComponentsRegistry register(ComponentFactory componentFactory) { 34 | return new MainComponentsRegistry(componentFactory); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /android/hermes/src/main/java/com/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.modules; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.soloader.SoLoader; 8 | import java.util.List; 9 | 10 | /** 11 | * Class responsible to load the TurboModules. This class has native methods and needs a 12 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 13 | * folder for you). 14 | * 15 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 16 | * `newArchEnabled` property). Is ignored otherwise. 17 | */ 18 | public class MainApplicationTurboModuleManagerDelegate 19 | extends ReactPackageTurboModuleManagerDelegate { 20 | 21 | private static volatile boolean sIsSoLibraryLoaded; 22 | 23 | protected MainApplicationTurboModuleManagerDelegate( 24 | ReactApplicationContext reactApplicationContext, List packages) { 25 | super(reactApplicationContext, packages); 26 | } 27 | 28 | protected native HybridData initHybrid(); 29 | 30 | native boolean canCreateTurboModule(String moduleName); 31 | 32 | public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { 33 | protected MainApplicationTurboModuleManagerDelegate build( 34 | ReactApplicationContext context, List packages) { 35 | return new MainApplicationTurboModuleManagerDelegate(context, packages); 36 | } 37 | } 38 | 39 | @Override 40 | protected synchronized void maybeLoadOtherSoLibraries() { 41 | if (!sIsSoLibraryLoaded) { 42 | // If you change the name of your application .so file in the Android.mk file, 43 | // make sure you update the name here as well. 44 | SoLoader.loadLibrary("rnbenchmark_appmodules"); 45 | sIsSoLibraryLoaded = true; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | THIS_DIR := $(call my-dir) 2 | 3 | include $(REACT_ANDROID_DIR)/Android-prebuilt.mk 4 | 5 | # If you wish to add a custom TurboModule or Fabric component in your app you 6 | # will have to include the following autogenerated makefile. 7 | # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_PATH := $(THIS_DIR) 11 | 12 | # You can customize the name of your application .so file here. 13 | LOCAL_MODULE := rnbenchmark_appmodules 14 | 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 16 | LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) 17 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 18 | 19 | # If you wish to add a custom TurboModule or Fabric component in your app you 20 | # will have to uncomment those lines to include the generated source 21 | # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) 22 | # 23 | # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 24 | # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) 25 | # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 26 | 27 | # Here you should add any native library you wish to depend on. 28 | LOCAL_SHARED_LIBRARIES := \ 29 | libfabricjni \ 30 | libfbjni \ 31 | libfolly_futures \ 32 | libfolly_json \ 33 | libglog \ 34 | libjsi \ 35 | libreact_codegen_rncore \ 36 | libreact_debug \ 37 | libreact_nativemodule_core \ 38 | libreact_render_componentregistry \ 39 | libreact_render_core \ 40 | libreact_render_debug \ 41 | libreact_render_graphics \ 42 | librrc_view \ 43 | libruntimeexecutor \ 44 | libturbomodulejsijni \ 45 | libyoga 46 | 47 | LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainApplicationModuleProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationModuleProvider.h" 2 | 3 | #include 4 | 5 | namespace facebook { 6 | namespace react { 7 | 8 | std::shared_ptr MainApplicationModuleProvider( 9 | const std::string moduleName, 10 | const JavaTurboModule::InitParams ¶ms) { 11 | // Here you can provide your own module provider for TurboModules coming from 12 | // either your application or from external libraries. The approach to follow 13 | // is similar to the following (for a library called `samplelibrary`: 14 | // 15 | // auto module = samplelibrary_ModuleProvider(moduleName, params); 16 | // if (module != nullptr) { 17 | // return module; 18 | // } 19 | // return rncore_ModuleProvider(moduleName, params); 20 | return rncore_ModuleProvider(moduleName, params); 21 | } 22 | 23 | } // namespace react 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainApplicationModuleProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | std::shared_ptr MainApplicationModuleProvider( 12 | const std::string moduleName, 13 | const JavaTurboModule::InitParams ¶ms); 14 | 15 | } // namespace react 16 | } // namespace facebook 17 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationTurboModuleManagerDelegate.h" 2 | #include "MainApplicationModuleProvider.h" 3 | 4 | namespace facebook { 5 | namespace react { 6 | 7 | jni::local_ref 8 | MainApplicationTurboModuleManagerDelegate::initHybrid( 9 | jni::alias_ref) { 10 | return makeCxxInstance(); 11 | } 12 | 13 | void MainApplicationTurboModuleManagerDelegate::registerNatives() { 14 | registerHybrid({ 15 | makeNativeMethod( 16 | "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), 17 | makeNativeMethod( 18 | "canCreateTurboModule", 19 | MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), 20 | }); 21 | } 22 | 23 | std::shared_ptr 24 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 25 | const std::string name, 26 | const std::shared_ptr jsInvoker) { 27 | // Not implemented yet: provide pure-C++ NativeModules here. 28 | return nullptr; 29 | } 30 | 31 | std::shared_ptr 32 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 33 | const std::string name, 34 | const JavaTurboModule::InitParams ¶ms) { 35 | return MainApplicationModuleProvider(name, params); 36 | } 37 | 38 | bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( 39 | std::string name) { 40 | return getTurboModule(name, nullptr) != nullptr || 41 | getTurboModule(name, {.moduleName = name}) != nullptr; 42 | } 43 | 44 | } // namespace react 45 | } // namespace facebook 46 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainApplicationTurboModuleManagerDelegate.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace facebook { 8 | namespace react { 9 | 10 | class MainApplicationTurboModuleManagerDelegate 11 | : public jni::HybridClass< 12 | MainApplicationTurboModuleManagerDelegate, 13 | TurboModuleManagerDelegate> { 14 | public: 15 | // Adapt it to the package you used for your Java class. 16 | static constexpr auto kJavaDescriptor = 17 | "Lcom/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; 18 | 19 | static jni::local_ref initHybrid(jni::alias_ref); 20 | 21 | static void registerNatives(); 22 | 23 | std::shared_ptr getTurboModule( 24 | const std::string name, 25 | const std::shared_ptr jsInvoker) override; 26 | std::shared_ptr getTurboModule( 27 | const std::string name, 28 | const JavaTurboModule::InitParams ¶ms) override; 29 | 30 | /** 31 | * Test-only method. Allows user to verify whether a TurboModule can be 32 | * created by instances of this class. 33 | */ 34 | bool canCreateTurboModule(std::string name); 35 | }; 36 | 37 | } // namespace react 38 | } // namespace facebook 39 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainComponentsRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "MainComponentsRegistry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} 12 | 13 | std::shared_ptr 14 | MainComponentsRegistry::sharedProviderRegistry() { 15 | auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); 16 | 17 | // Custom Fabric Components go here. You can register custom 18 | // components coming from your App or from 3rd party libraries here. 19 | // 20 | // providerRegistry->add(concreteComponentDescriptorProvider< 21 | // AocViewerComponentDescriptor>()); 22 | return providerRegistry; 23 | } 24 | 25 | jni::local_ref 26 | MainComponentsRegistry::initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate) { 29 | auto instance = makeCxxInstance(delegate); 30 | 31 | auto buildRegistryFunction = 32 | [](EventDispatcher::Weak const &eventDispatcher, 33 | ContextContainer::Shared const &contextContainer) 34 | -> ComponentDescriptorRegistry::Shared { 35 | auto registry = MainComponentsRegistry::sharedProviderRegistry() 36 | ->createComponentDescriptorRegistry( 37 | {eventDispatcher, contextContainer}); 38 | 39 | auto mutableRegistry = 40 | std::const_pointer_cast(registry); 41 | 42 | mutableRegistry->setFallbackComponentDescriptor( 43 | std::make_shared( 44 | ComponentDescriptorParameters{ 45 | eventDispatcher, contextContainer, nullptr})); 46 | 47 | return registry; 48 | }; 49 | 50 | delegate->buildRegistryFunction = buildRegistryFunction; 51 | return instance; 52 | } 53 | 54 | void MainComponentsRegistry::registerNatives() { 55 | registerHybrid({ 56 | makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), 57 | }); 58 | } 59 | 60 | } // namespace react 61 | } // namespace facebook 62 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/MainComponentsRegistry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | class MainComponentsRegistry 12 | : public facebook::jni::HybridClass { 13 | public: 14 | // Adapt it to the package you used for your Java class. 15 | constexpr static auto kJavaDescriptor = 16 | "Lcom/rnbenchmark/newarchitecture/components/MainComponentsRegistry;"; 17 | 18 | static void registerNatives(); 19 | 20 | MainComponentsRegistry(ComponentFactory *delegate); 21 | 22 | private: 23 | static std::shared_ptr 24 | sharedProviderRegistry(); 25 | 26 | static jni::local_ref initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate); 29 | }; 30 | 31 | } // namespace react 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /android/hermes/src/main/jni/OnLoad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MainApplicationTurboModuleManagerDelegate.h" 3 | #include "MainComponentsRegistry.h" 4 | 5 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { 6 | return facebook::jni::initialize(vm, [] { 7 | facebook::react::MainApplicationTurboModuleManagerDelegate:: 8 | registerNatives(); 9 | facebook::react::MainComponentsRegistry::registerNatives(); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /android/hermes/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/hermes/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/hermes/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RNBenchmark 3 | 4 | -------------------------------------------------------------------------------- /android/hermes/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android/jsc/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.rnbenchmark", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.rnbenchmark", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /android/jsc/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /android/jsc/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/debug.keystore -------------------------------------------------------------------------------- /android/jsc/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /android/jsc/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /android/jsc/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/jsc/src/main/java/com/rnbenchmark/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.ReactRootView; 6 | 7 | public class MainActivity extends ReactActivity { 8 | 9 | /** 10 | * Returns the name of the main component registered from JavaScript. This is used to schedule 11 | * rendering of the component. 12 | */ 13 | @Override 14 | protected String getMainComponentName() { 15 | return "RNBenchmark"; 16 | } 17 | 18 | /** 19 | * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and 20 | * you can specify the rendered you wish to use (Fabric or the older renderer). 21 | */ 22 | @Override 23 | protected ReactActivityDelegate createReactActivityDelegate() { 24 | return new MainActivityDelegate(this, getMainComponentName()); 25 | } 26 | 27 | public static class MainActivityDelegate extends ReactActivityDelegate { 28 | public MainActivityDelegate(ReactActivity activity, String mainComponentName) { 29 | super(activity, mainComponentName); 30 | } 31 | 32 | @Override 33 | protected ReactRootView createRootView() { 34 | ReactRootView reactRootView = new ReactRootView(getContext()); 35 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 36 | reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); 37 | return reactRootView; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android/jsc/src/main/java/com/rnbenchmark/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.facebook.react.PackageList; 8 | import com.facebook.react.ReactApplication; 9 | import com.facebook.react.ReactInstanceManager; 10 | import com.facebook.react.ReactNativeHost; 11 | import com.facebook.react.ReactPackage; 12 | import com.facebook.react.config.ReactFeatureFlags; 13 | import com.facebook.react.bridge.ReactMarker; 14 | import com.facebook.react.bridge.ReactMarkerConstants; 15 | import com.facebook.soloader.SoLoader; 16 | import com.rnbenchmark.newarchitecture.MainApplicationReactNativeHost; 17 | 18 | import java.lang.reflect.InvocationTargetException; 19 | import java.util.List; 20 | 21 | import javax.annotation.Nullable; 22 | 23 | public class MainApplication extends Application implements 24 | ReactApplication, 25 | ReactMarker.MarkerListener { 26 | 27 | private long mTTIStartTime; 28 | private long mTTIEndTime; 29 | 30 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 31 | @Override 32 | public boolean getUseDeveloperSupport() { 33 | return BuildConfig.DEBUG; 34 | } 35 | 36 | @Override 37 | protected List getPackages() { 38 | @SuppressWarnings("UnnecessaryLocalVariable") 39 | List packages = new PackageList(this).getPackages(); 40 | // Packages that cannot be autolinked yet can be added manually here, for example: 41 | // packages.add(new MyReactNativePackage()); 42 | return packages; 43 | } 44 | 45 | @Override 46 | protected String getJSMainModuleName() { 47 | return "index"; 48 | } 49 | }; 50 | 51 | private final ReactNativeHost mNewArchitectureNativeHost = 52 | new MainApplicationReactNativeHost(this); 53 | 54 | @Override 55 | public ReactNativeHost getReactNativeHost() { 56 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 57 | return mNewArchitectureNativeHost; 58 | } else { 59 | return mReactNativeHost; 60 | } 61 | } 62 | 63 | @Override 64 | public void onCreate() { 65 | super.onCreate(); 66 | ReactMarker.addListener(this); 67 | // If you opted-in for the New Architecture, we enable the TurboModule system 68 | ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 69 | SoLoader.init(this, /* native exopackage */ false); 70 | // initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 71 | } 72 | 73 | /** 74 | * Loads Flipper in React Native templates. 75 | * 76 | * @param context 77 | */ 78 | private static void initializeFlipper( 79 | Context context, ReactInstanceManager reactInstanceManager) { 80 | if (BuildConfig.DEBUG) { 81 | try { 82 | /* 83 | We use reflection here to pick up the class that initializes Flipper, 84 | since Flipper library is not available in release mode 85 | */ 86 | Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); 87 | aClass 88 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 89 | .invoke(null, context, reactInstanceManager); 90 | } catch (ClassNotFoundException e) { 91 | e.printStackTrace(); 92 | } catch (NoSuchMethodException e) { 93 | e.printStackTrace(); 94 | } catch (IllegalAccessException e) { 95 | e.printStackTrace(); 96 | } catch (InvocationTargetException e) { 97 | e.printStackTrace(); 98 | } 99 | } 100 | } 101 | 102 | @Override 103 | public void onTerminate() { 104 | ReactMarker.removeListener(this); 105 | super.onTerminate(); 106 | } 107 | 108 | // 109 | // ReactMarker.MarkerListener implementations 110 | // 111 | @Override 112 | public void logMarker(ReactMarkerConstants name, @Nullable String tag, int instanceKey) { 113 | if (name == ReactMarkerConstants.GET_REACT_INSTANCE_MANAGER_START) { 114 | mTTIStartTime = System.currentTimeMillis(); 115 | } else if (name == ReactMarkerConstants.CONTENT_APPEARED) { 116 | mTTIEndTime = System.currentTimeMillis(); 117 | Log.i("MeasureTTI", "TTI=" + (mTTIEndTime - mTTIStartTime)); 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /android/jsc/src/main/java/com/rnbenchmark/newarchitecture/MainApplicationReactNativeHost.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture; 2 | 3 | import android.app.Application; 4 | import androidx.annotation.NonNull; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactInstanceManager; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 10 | import com.facebook.react.bridge.JSIModulePackage; 11 | import com.facebook.react.bridge.JSIModuleProvider; 12 | import com.facebook.react.bridge.JSIModuleSpec; 13 | import com.facebook.react.bridge.JSIModuleType; 14 | import com.facebook.react.bridge.JavaScriptContextHolder; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.UIManager; 17 | import com.facebook.react.fabric.ComponentFactory; 18 | import com.facebook.react.fabric.CoreComponentsRegistry; 19 | import com.facebook.react.fabric.EmptyReactNativeConfig; 20 | import com.facebook.react.fabric.FabricJSIModuleProvider; 21 | import com.facebook.react.uimanager.ViewManagerRegistry; 22 | import com.rnbenchmark.BuildConfig; 23 | import com.rnbenchmark.newarchitecture.components.MainComponentsRegistry; 24 | import com.rnbenchmark.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both 30 | * TurboModule delegates and the Fabric Renderer. 31 | * 32 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 33 | * `newArchEnabled` property). Is ignored otherwise. 34 | */ 35 | public class MainApplicationReactNativeHost extends ReactNativeHost { 36 | public MainApplicationReactNativeHost(Application application) { 37 | super(application); 38 | } 39 | 40 | @Override 41 | public boolean getUseDeveloperSupport() { 42 | return BuildConfig.DEBUG; 43 | } 44 | 45 | @Override 46 | protected List getPackages() { 47 | List packages = new PackageList(this).getPackages(); 48 | // Packages that cannot be autolinked yet can be added manually here, for example: 49 | // packages.add(new MyReactNativePackage()); 50 | // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: 51 | // packages.add(new TurboReactPackage() { ... }); 52 | // If you have custom Fabric Components, their ViewManagers should also be loaded here 53 | // inside a ReactPackage. 54 | return packages; 55 | } 56 | 57 | @Override 58 | protected String getJSMainModuleName() { 59 | return "index"; 60 | } 61 | 62 | @NonNull 63 | @Override 64 | protected ReactPackageTurboModuleManagerDelegate.Builder 65 | getReactPackageTurboModuleManagerDelegateBuilder() { 66 | // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary 67 | // for the new architecture and to use TurboModules correctly. 68 | return new MainApplicationTurboModuleManagerDelegate.Builder(); 69 | } 70 | 71 | @Override 72 | protected JSIModulePackage getJSIModulePackage() { 73 | return new JSIModulePackage() { 74 | @Override 75 | public List getJSIModules( 76 | final ReactApplicationContext reactApplicationContext, 77 | final JavaScriptContextHolder jsContext) { 78 | final List specs = new ArrayList<>(); 79 | 80 | // Here we provide a new JSIModuleSpec that will be responsible of providing the 81 | // custom Fabric Components. 82 | specs.add( 83 | new JSIModuleSpec() { 84 | @Override 85 | public JSIModuleType getJSIModuleType() { 86 | return JSIModuleType.UIManager; 87 | } 88 | 89 | @Override 90 | public JSIModuleProvider getJSIModuleProvider() { 91 | final ComponentFactory componentFactory = new ComponentFactory(); 92 | CoreComponentsRegistry.register(componentFactory); 93 | 94 | // Here we register a Components Registry. 95 | // The one that is generated with the template contains no components 96 | // and just provides you the one from React Native core. 97 | MainComponentsRegistry.register(componentFactory); 98 | 99 | final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); 100 | 101 | ViewManagerRegistry viewManagerRegistry = 102 | new ViewManagerRegistry( 103 | reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); 104 | 105 | return new FabricJSIModuleProvider( 106 | reactApplicationContext, 107 | componentFactory, 108 | new EmptyReactNativeConfig(), 109 | viewManagerRegistry); 110 | } 111 | }); 112 | return specs; 113 | } 114 | }; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /android/jsc/src/main/java/com/rnbenchmark/newarchitecture/components/MainComponentsRegistry.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.components; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.proguard.annotations.DoNotStrip; 5 | import com.facebook.react.fabric.ComponentFactory; 6 | import com.facebook.soloader.SoLoader; 7 | 8 | /** 9 | * Class responsible to load the custom Fabric Components. This class has native methods and needs a 10 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 11 | * folder for you). 12 | * 13 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 14 | * `newArchEnabled` property). Is ignored otherwise. 15 | */ 16 | @DoNotStrip 17 | public class MainComponentsRegistry { 18 | static { 19 | SoLoader.loadLibrary("fabricjni"); 20 | } 21 | 22 | @DoNotStrip private final HybridData mHybridData; 23 | 24 | @DoNotStrip 25 | private native HybridData initHybrid(ComponentFactory componentFactory); 26 | 27 | @DoNotStrip 28 | private MainComponentsRegistry(ComponentFactory componentFactory) { 29 | mHybridData = initHybrid(componentFactory); 30 | } 31 | 32 | @DoNotStrip 33 | public static MainComponentsRegistry register(ComponentFactory componentFactory) { 34 | return new MainComponentsRegistry(componentFactory); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /android/jsc/src/main/java/com/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.modules; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.soloader.SoLoader; 8 | import java.util.List; 9 | 10 | /** 11 | * Class responsible to load the TurboModules. This class has native methods and needs a 12 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 13 | * folder for you). 14 | * 15 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 16 | * `newArchEnabled` property). Is ignored otherwise. 17 | */ 18 | public class MainApplicationTurboModuleManagerDelegate 19 | extends ReactPackageTurboModuleManagerDelegate { 20 | 21 | private static volatile boolean sIsSoLibraryLoaded; 22 | 23 | protected MainApplicationTurboModuleManagerDelegate( 24 | ReactApplicationContext reactApplicationContext, List packages) { 25 | super(reactApplicationContext, packages); 26 | } 27 | 28 | protected native HybridData initHybrid(); 29 | 30 | native boolean canCreateTurboModule(String moduleName); 31 | 32 | public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { 33 | protected MainApplicationTurboModuleManagerDelegate build( 34 | ReactApplicationContext context, List packages) { 35 | return new MainApplicationTurboModuleManagerDelegate(context, packages); 36 | } 37 | } 38 | 39 | @Override 40 | protected synchronized void maybeLoadOtherSoLibraries() { 41 | if (!sIsSoLibraryLoaded) { 42 | // If you change the name of your application .so file in the Android.mk file, 43 | // make sure you update the name here as well. 44 | SoLoader.loadLibrary("rnbenchmark_appmodules"); 45 | sIsSoLibraryLoaded = true; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | THIS_DIR := $(call my-dir) 2 | 3 | include $(REACT_ANDROID_DIR)/Android-prebuilt.mk 4 | 5 | # If you wish to add a custom TurboModule or Fabric component in your app you 6 | # will have to include the following autogenerated makefile. 7 | # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_PATH := $(THIS_DIR) 11 | 12 | # You can customize the name of your application .so file here. 13 | LOCAL_MODULE := rnbenchmark_appmodules 14 | 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 16 | LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) 17 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 18 | 19 | # If you wish to add a custom TurboModule or Fabric component in your app you 20 | # will have to uncomment those lines to include the generated source 21 | # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) 22 | # 23 | # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 24 | # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) 25 | # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 26 | 27 | # Here you should add any native library you wish to depend on. 28 | LOCAL_SHARED_LIBRARIES := \ 29 | libfabricjni \ 30 | libfbjni \ 31 | libfolly_futures \ 32 | libfolly_json \ 33 | libglog \ 34 | libjsi \ 35 | libreact_codegen_rncore \ 36 | libreact_debug \ 37 | libreact_nativemodule_core \ 38 | libreact_render_componentregistry \ 39 | libreact_render_core \ 40 | libreact_render_debug \ 41 | libreact_render_graphics \ 42 | librrc_view \ 43 | libruntimeexecutor \ 44 | libturbomodulejsijni \ 45 | libyoga 46 | 47 | LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainApplicationModuleProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationModuleProvider.h" 2 | 3 | #include 4 | 5 | namespace facebook { 6 | namespace react { 7 | 8 | std::shared_ptr MainApplicationModuleProvider( 9 | const std::string moduleName, 10 | const JavaTurboModule::InitParams ¶ms) { 11 | // Here you can provide your own module provider for TurboModules coming from 12 | // either your application or from external libraries. The approach to follow 13 | // is similar to the following (for a library called `samplelibrary`: 14 | // 15 | // auto module = samplelibrary_ModuleProvider(moduleName, params); 16 | // if (module != nullptr) { 17 | // return module; 18 | // } 19 | // return rncore_ModuleProvider(moduleName, params); 20 | return rncore_ModuleProvider(moduleName, params); 21 | } 22 | 23 | } // namespace react 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainApplicationModuleProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | std::shared_ptr MainApplicationModuleProvider( 12 | const std::string moduleName, 13 | const JavaTurboModule::InitParams ¶ms); 14 | 15 | } // namespace react 16 | } // namespace facebook 17 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationTurboModuleManagerDelegate.h" 2 | #include "MainApplicationModuleProvider.h" 3 | 4 | namespace facebook { 5 | namespace react { 6 | 7 | jni::local_ref 8 | MainApplicationTurboModuleManagerDelegate::initHybrid( 9 | jni::alias_ref) { 10 | return makeCxxInstance(); 11 | } 12 | 13 | void MainApplicationTurboModuleManagerDelegate::registerNatives() { 14 | registerHybrid({ 15 | makeNativeMethod( 16 | "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), 17 | makeNativeMethod( 18 | "canCreateTurboModule", 19 | MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), 20 | }); 21 | } 22 | 23 | std::shared_ptr 24 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 25 | const std::string name, 26 | const std::shared_ptr jsInvoker) { 27 | // Not implemented yet: provide pure-C++ NativeModules here. 28 | return nullptr; 29 | } 30 | 31 | std::shared_ptr 32 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 33 | const std::string name, 34 | const JavaTurboModule::InitParams ¶ms) { 35 | return MainApplicationModuleProvider(name, params); 36 | } 37 | 38 | bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( 39 | std::string name) { 40 | return getTurboModule(name, nullptr) != nullptr || 41 | getTurboModule(name, {.moduleName = name}) != nullptr; 42 | } 43 | 44 | } // namespace react 45 | } // namespace facebook 46 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainApplicationTurboModuleManagerDelegate.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace facebook { 8 | namespace react { 9 | 10 | class MainApplicationTurboModuleManagerDelegate 11 | : public jni::HybridClass< 12 | MainApplicationTurboModuleManagerDelegate, 13 | TurboModuleManagerDelegate> { 14 | public: 15 | // Adapt it to the package you used for your Java class. 16 | static constexpr auto kJavaDescriptor = 17 | "Lcom/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; 18 | 19 | static jni::local_ref initHybrid(jni::alias_ref); 20 | 21 | static void registerNatives(); 22 | 23 | std::shared_ptr getTurboModule( 24 | const std::string name, 25 | const std::shared_ptr jsInvoker) override; 26 | std::shared_ptr getTurboModule( 27 | const std::string name, 28 | const JavaTurboModule::InitParams ¶ms) override; 29 | 30 | /** 31 | * Test-only method. Allows user to verify whether a TurboModule can be 32 | * created by instances of this class. 33 | */ 34 | bool canCreateTurboModule(std::string name); 35 | }; 36 | 37 | } // namespace react 38 | } // namespace facebook 39 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainComponentsRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "MainComponentsRegistry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} 12 | 13 | std::shared_ptr 14 | MainComponentsRegistry::sharedProviderRegistry() { 15 | auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); 16 | 17 | // Custom Fabric Components go here. You can register custom 18 | // components coming from your App or from 3rd party libraries here. 19 | // 20 | // providerRegistry->add(concreteComponentDescriptorProvider< 21 | // AocViewerComponentDescriptor>()); 22 | return providerRegistry; 23 | } 24 | 25 | jni::local_ref 26 | MainComponentsRegistry::initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate) { 29 | auto instance = makeCxxInstance(delegate); 30 | 31 | auto buildRegistryFunction = 32 | [](EventDispatcher::Weak const &eventDispatcher, 33 | ContextContainer::Shared const &contextContainer) 34 | -> ComponentDescriptorRegistry::Shared { 35 | auto registry = MainComponentsRegistry::sharedProviderRegistry() 36 | ->createComponentDescriptorRegistry( 37 | {eventDispatcher, contextContainer}); 38 | 39 | auto mutableRegistry = 40 | std::const_pointer_cast(registry); 41 | 42 | mutableRegistry->setFallbackComponentDescriptor( 43 | std::make_shared( 44 | ComponentDescriptorParameters{ 45 | eventDispatcher, contextContainer, nullptr})); 46 | 47 | return registry; 48 | }; 49 | 50 | delegate->buildRegistryFunction = buildRegistryFunction; 51 | return instance; 52 | } 53 | 54 | void MainComponentsRegistry::registerNatives() { 55 | registerHybrid({ 56 | makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), 57 | }); 58 | } 59 | 60 | } // namespace react 61 | } // namespace facebook 62 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/MainComponentsRegistry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | class MainComponentsRegistry 12 | : public facebook::jni::HybridClass { 13 | public: 14 | // Adapt it to the package you used for your Java class. 15 | constexpr static auto kJavaDescriptor = 16 | "Lcom/rnbenchmark/newarchitecture/components/MainComponentsRegistry;"; 17 | 18 | static void registerNatives(); 19 | 20 | MainComponentsRegistry(ComponentFactory *delegate); 21 | 22 | private: 23 | static std::shared_ptr 24 | sharedProviderRegistry(); 25 | 26 | static jni::local_ref initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate); 29 | }; 30 | 31 | } // namespace react 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /android/jsc/src/main/jni/OnLoad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MainApplicationTurboModuleManagerDelegate.h" 3 | #include "MainComponentsRegistry.h" 4 | 5 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { 6 | return facebook::jni::initialize(vm, [] { 7 | facebook::react::MainApplicationTurboModuleManagerDelegate:: 8 | registerNatives(); 9 | facebook::react::MainComponentsRegistry::registerNatives(); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /android/jsc/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/jsc/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/jsc/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RNBenchmark 3 | 4 | -------------------------------------------------------------------------------- /android/jsc/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'RNBenchmark' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':jsc' 4 | include ':v8' 5 | include ':hermes' 6 | includeBuild('../node_modules/react-native-gradle-plugin') 7 | 8 | if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") { 9 | include(":ReactAndroid") 10 | project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid') 11 | } 12 | 13 | include(':react-native-v8') 14 | project(':react-native-v8').projectDir = file('../node_modules/react-native-v8/android') 15 | -------------------------------------------------------------------------------- /android/v8/BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.rnbenchmark", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.rnbenchmark", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /android/v8/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: "com.android.application" 2 | 3 | repositories { 4 | maven { 5 | url("$rootDir/../node_modules/react-native-v8/dist") 6 | content { 7 | includeGroup "com.facebook.react" 8 | } 9 | } 10 | 11 | maven { 12 | url(project.findProperty("MAVEN_REPO") ?: "$rootDir/../node_modules/v8-android/dist") 13 | content { 14 | includeGroup "org.chromium" 15 | } 16 | } 17 | } 18 | 19 | import com.android.build.OutputFile 20 | 21 | /** 22 | * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets 23 | * and bundleReleaseJsAndAssets). 24 | * These basically call `react-native bundle` with the correct arguments during the Android build 25 | * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the 26 | * bundle directly from the development server. Below you can see all the possible configurations 27 | * and their defaults. If you decide to add a configuration block, make sure to add it before the 28 | * `apply from: "../../node_modules/react-native/react.gradle"` line. 29 | * 30 | * project.ext.react = [ 31 | * // the name of the generated asset file containing your JS bundle 32 | * bundleAssetName: "index.android.bundle", 33 | * 34 | * // the entry file for bundle generation. If none specified and 35 | * // "index.android.js" exists, it will be used. Otherwise "index.js" is 36 | * // default. Can be overridden with ENTRY_FILE environment variable. 37 | * entryFile: "index.android.js", 38 | * 39 | * // https://reactnative.dev/docs/performance#enable-the-ram-format 40 | * bundleCommand: "ram-bundle", 41 | * 42 | * // whether to bundle JS and assets in debug mode 43 | * bundleInDebug: false, 44 | * 45 | * // whether to bundle JS and assets in release mode 46 | * bundleInRelease: true, 47 | * 48 | * // whether to bundle JS and assets in another build variant (if configured). 49 | * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants 50 | * // The configuration property can be in the following formats 51 | * // 'bundleIn${productFlavor}${buildType}' 52 | * // 'bundleIn${buildType}' 53 | * // bundleInFreeDebug: true, 54 | * // bundleInPaidRelease: true, 55 | * // bundleInBeta: true, 56 | * 57 | * // whether to disable dev mode in custom build variants (by default only disabled in release) 58 | * // for example: to disable dev mode in the staging build type (if configured) 59 | * devDisabledInStaging: true, 60 | * // The configuration property can be in the following formats 61 | * // 'devDisabledIn${productFlavor}${buildType}' 62 | * // 'devDisabledIn${buildType}' 63 | * 64 | * // the root of your project, i.e. where "package.json" lives 65 | * root: "../../", 66 | * 67 | * // where to put the JS bundle asset in debug mode 68 | * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", 69 | * 70 | * // where to put the JS bundle asset in release mode 71 | * jsBundleDirRelease: "$buildDir/intermediates/assets/release", 72 | * 73 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 74 | * // require('./image.png')), in debug mode 75 | * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", 76 | * 77 | * // where to put drawable resources / React Native assets, e.g. the ones you use via 78 | * // require('./image.png')), in release mode 79 | * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", 80 | * 81 | * // by default the gradle tasks are skipped if none of the JS files or assets change; this means 82 | * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to 83 | * // date; if you have any other folders that you want to ignore for performance reasons (gradle 84 | * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ 85 | * // for example, you might want to remove it from here. 86 | * inputExcludes: ["android/**", "ios/**"], 87 | * 88 | * // override which node gets called and with what additional arguments 89 | * nodeExecutableAndArgs: ["node"], 90 | * 91 | * // supply additional arguments to the packager 92 | * extraPackagerArgs: [] 93 | * ] 94 | */ 95 | 96 | project.ext.react = [ 97 | enableHermes: false, // clean and rebuild if changing 98 | // bundleCommand: "ram-bundle", 99 | // extraPackagerArgs: ["--indexed-ram-bundle"], 100 | ] 101 | 102 | apply from: "../../node_modules/react-native/react.gradle" 103 | 104 | /** 105 | * Set this to true to create two separate APKs instead of one: 106 | * - An APK that only works on ARM devices 107 | * - An APK that only works on x86 devices 108 | * The advantage is the size of the APK is reduced by about 4MB. 109 | * Upload all the APKs to the Play Store and people will download 110 | * the correct one based on the CPU architecture of their device. 111 | */ 112 | def enableSeparateBuildPerCPUArchitecture = project.findProperty('ABI_BASED_APK') == 'true' 113 | 114 | /** 115 | * Run Proguard to shrink the Java bytecode in release builds. 116 | */ 117 | def enableProguardInReleaseBuilds = false 118 | 119 | /** 120 | * The preferred build flavor of JavaScriptCore. 121 | * 122 | * For example, to use the international variant, you can use: 123 | * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` 124 | * 125 | * The international variant includes ICU i18n library and necessary data 126 | * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that 127 | * give correct results when using with locales other than en-US. Note that 128 | * this variant is about 6MiB larger per architecture than default. 129 | */ 130 | def jscFlavor = 'org.webkit:android-jsc:+' 131 | 132 | /** 133 | * Whether to enable the Hermes VM. 134 | * 135 | * This should be set on project.ext.react and that value will be read here. If it is not set 136 | * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode 137 | * and the benefits of using Hermes will therefore be sharply reduced. 138 | */ 139 | def enableHermes = project.ext.react.get("enableHermes", false); 140 | 141 | /** 142 | * Architectures to build native code for. 143 | */ 144 | def reactNativeArchitectures() { 145 | def value = project.getProperties().get("reactNativeArchitectures") 146 | return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"] 147 | } 148 | 149 | android { 150 | ndkVersion rootProject.ext.ndkVersion 151 | 152 | compileSdkVersion rootProject.ext.compileSdkVersion 153 | 154 | defaultConfig { 155 | applicationId "com.rnbenchmark.v8" 156 | minSdkVersion rootProject.ext.minSdkVersion 157 | targetSdkVersion rootProject.ext.targetSdkVersion 158 | versionCode 1 159 | versionName "1.0" 160 | buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString() 161 | 162 | if (isNewArchitectureEnabled()) { 163 | // We configure the NDK build only if you decide to opt-in for the New Architecture. 164 | externalNativeBuild { 165 | ndkBuild { 166 | arguments "APP_PLATFORM=android-21", 167 | "APP_STL=c++_shared", 168 | "NDK_TOOLCHAIN_VERSION=clang", 169 | "GENERATED_SRC_DIR=$buildDir/generated/source", 170 | "PROJECT_BUILD_DIR=$buildDir", 171 | "REACT_ANDROID_DIR=$rootDir/../node_modules/react-native/ReactAndroid", 172 | "REACT_ANDROID_BUILD_DIR=$rootDir/../node_modules/react-native/ReactAndroid/build" 173 | cFlags "-Wall", "-Werror", "-fexceptions", "-frtti", "-DWITH_INSPECTOR=1" 174 | cppFlags "-std=c++17" 175 | // Make sure this target name is the same you specify inside the 176 | // src/main/jni/Android.mk file for the `LOCAL_MODULE` variable. 177 | targets "rnbenchmark_appmodules" 178 | 179 | // Fix for windows limit on number of character in file paths and in command lines 180 | if (Os.isFamily(Os.FAMILY_WINDOWS)) { 181 | arguments "NDK_OUT=${rootProject.projectDir.getParent()}\\.cxx", 182 | "NDK_APP_SHORT_COMMANDS=true" 183 | } 184 | } 185 | } 186 | if (!enableSeparateBuildPerCPUArchitecture) { 187 | ndk { 188 | abiFilters (*reactNativeArchitectures()) 189 | } 190 | } 191 | } 192 | } 193 | 194 | if (isNewArchitectureEnabled()) { 195 | // We configure the NDK build only if you decide to opt-in for the New Architecture. 196 | externalNativeBuild { 197 | ndkBuild { 198 | path "$projectDir/src/main/jni/Android.mk" 199 | } 200 | } 201 | def reactAndroidProjectDir = project(':ReactAndroid').projectDir 202 | def packageReactNdkDebugLibs = tasks.register("packageReactNdkDebugLibs", Copy) { 203 | dependsOn(":ReactAndroid:packageReactNdkDebugLibsForBuck") 204 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") 205 | into("$buildDir/react-ndk/exported") 206 | } 207 | def packageReactNdkReleaseLibs = tasks.register("packageReactNdkReleaseLibs", Copy) { 208 | dependsOn(":ReactAndroid:packageReactNdkReleaseLibsForBuck") 209 | from("$reactAndroidProjectDir/src/main/jni/prebuilt/lib") 210 | into("$buildDir/react-ndk/exported") 211 | } 212 | afterEvaluate { 213 | // If you wish to add a custom TurboModule or component locally, 214 | // you should uncomment this line. 215 | // preBuild.dependsOn("generateCodegenArtifactsFromSchema") 216 | preDebugBuild.dependsOn(packageReactNdkDebugLibs) 217 | preReleaseBuild.dependsOn(packageReactNdkReleaseLibs) 218 | 219 | // Due to a bug inside AGP, we have to explicitly set a dependency 220 | // between configureNdkBuild* tasks and the preBuild tasks. 221 | // This can be removed once this is solved: https://issuetracker.google.com/issues/207403732 222 | configureNdkBuildRelease.dependsOn(preReleaseBuild) 223 | configureNdkBuildDebug.dependsOn(preDebugBuild) 224 | reactNativeArchitectures().each { architecture -> 225 | tasks.findByName("configureNdkBuildDebug[${architecture}]")?.configure { 226 | dependsOn("preDebugBuild") 227 | } 228 | tasks.findByName("configureNdkBuildRelease[${architecture}]")?.configure { 229 | dependsOn("preReleaseBuild") 230 | } 231 | } 232 | } 233 | } 234 | 235 | splits { 236 | abi { 237 | reset() 238 | enable enableSeparateBuildPerCPUArchitecture 239 | universalApk false // If true, also generate a universal APK 240 | include (*reactNativeArchitectures()) 241 | } 242 | } 243 | signingConfigs { 244 | debug { 245 | storeFile file('debug.keystore') 246 | storePassword 'android' 247 | keyAlias 'androiddebugkey' 248 | keyPassword 'android' 249 | } 250 | } 251 | buildTypes { 252 | debug { 253 | signingConfig signingConfigs.debug 254 | } 255 | release { 256 | // Caution! In production, you need to generate your own keystore file. 257 | // see https://reactnative.dev/docs/signed-apk-android. 258 | signingConfig signingConfigs.debug 259 | minifyEnabled enableProguardInReleaseBuilds 260 | proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" 261 | } 262 | } 263 | 264 | // applicationVariants are e.g. debug, release 265 | applicationVariants.all { variant -> 266 | variant.outputs.each { output -> 267 | // For each separate APK per architecture, set a unique version code as described here: 268 | // https://developer.android.com/studio/build/configure-apk-splits.html 269 | // Example: versionCode 1 will generate 1001 for armeabi-v7a, 1002 for x86, etc. 270 | def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] 271 | def abi = output.getFilter(OutputFile.ABI) 272 | if (abi != null) { // null for the universal-debug, universal-release variants 273 | output.versionCodeOverride = 274 | defaultConfig.versionCode * 1000 + versionCodes.get(abi) 275 | } 276 | 277 | } 278 | } 279 | 280 | packagingOptions { 281 | exclude '**/libjsc*' 282 | exclude '**/libhermes*' 283 | } 284 | } 285 | 286 | dependencies { 287 | implementation fileTree(dir: "libs", include: ["*.jar"]) 288 | implementation "com.facebook.react:react-native:+" // From node_modules 289 | //noinspection GradleDynamicVersion 290 | implementation project(':react-native-v8') 291 | 292 | implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" 293 | } 294 | 295 | if (isNewArchitectureEnabled()) { 296 | // If new architecture is enabled, we let you build RN from source 297 | // Otherwise we fallback to a prebuilt .aar bundled in the NPM package. 298 | // This will be applied to all the imported transtitive dependency. 299 | configurations.all { 300 | resolutionStrategy.dependencySubstitution { 301 | substitute(module("com.facebook.react:react-native")) 302 | .using(project(":ReactAndroid")).because("On New Architecture we're building React Native from source") 303 | } 304 | } 305 | } 306 | 307 | // Run this once to be able to run the application with BUCK 308 | // puts all compile dependencies into folder libs for BUCK to use 309 | task copyDownloadableDepsToLibs(type: Copy) { 310 | from configurations.implementation 311 | into 'libs' 312 | } 313 | 314 | apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) 315 | 316 | def isNewArchitectureEnabled() { 317 | // To opt-in for the New Architecture, you can either: 318 | // - Set `newArchEnabled` to true inside the `gradle.properties` file 319 | // - Invoke gradle with `-newArchEnabled=true` 320 | // - Set an environment variable `ORG_GRADLE_PROJECT_newArchEnabled=true` 321 | return project.hasProperty("newArchEnabled") && project.newArchEnabled == "true" 322 | } 323 | 324 | if (findProperty("v8.cacheMode") == "prebuilt") { 325 | apply from: "../../node_modules/react-native-v8/android/mkcodecache.gradle" 326 | } 327 | -------------------------------------------------------------------------------- /android/v8/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /android/v8/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/debug.keystore -------------------------------------------------------------------------------- /android/v8/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /android/v8/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /android/v8/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 13 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /android/v8/src/main/java/com/rnbenchmark/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.ReactRootView; 6 | 7 | public class MainActivity extends ReactActivity { 8 | 9 | /** 10 | * Returns the name of the main component registered from JavaScript. This is used to schedule 11 | * rendering of the component. 12 | */ 13 | @Override 14 | protected String getMainComponentName() { 15 | return "RNBenchmark"; 16 | } 17 | 18 | /** 19 | * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and 20 | * you can specify the rendered you wish to use (Fabric or the older renderer). 21 | */ 22 | @Override 23 | protected ReactActivityDelegate createReactActivityDelegate() { 24 | return new MainActivityDelegate(this, getMainComponentName()); 25 | } 26 | 27 | public static class MainActivityDelegate extends ReactActivityDelegate { 28 | public MainActivityDelegate(ReactActivity activity, String mainComponentName) { 29 | super(activity, mainComponentName); 30 | } 31 | 32 | @Override 33 | protected ReactRootView createRootView() { 34 | ReactRootView reactRootView = new ReactRootView(getContext()); 35 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 36 | reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); 37 | return reactRootView; 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /android/v8/src/main/java/com/rnbenchmark/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark; 2 | 3 | import android.app.Application; 4 | import android.content.Context; 5 | import android.util.Log; 6 | 7 | import com.facebook.react.PackageList; 8 | import com.facebook.react.ReactApplication; 9 | import com.facebook.react.ReactInstanceManager; 10 | import com.facebook.react.ReactNativeHost; 11 | import com.facebook.react.ReactPackage; 12 | import com.facebook.react.bridge.JavaScriptExecutorFactory; 13 | import com.facebook.react.config.ReactFeatureFlags; 14 | import com.facebook.react.bridge.ReactMarker; 15 | import com.facebook.react.bridge.ReactMarkerConstants; 16 | import com.facebook.react.modules.systeminfo.AndroidInfoHelpers; 17 | import com.facebook.soloader.SoLoader; 18 | import com.rnbenchmark.newarchitecture.MainApplicationReactNativeHost; 19 | 20 | import java.lang.reflect.InvocationTargetException; 21 | import java.util.List; 22 | 23 | import javax.annotation.Nullable; 24 | 25 | import io.csie.kudo.reactnative.v8.ReactNativeV8Package; 26 | import io.csie.kudo.reactnative.v8.executor.V8ExecutorFactory; 27 | 28 | public class MainApplication extends Application implements 29 | ReactApplication, 30 | ReactMarker.MarkerListener { 31 | 32 | private long mTTIStartTime; 33 | private long mTTIEndTime; 34 | 35 | private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { 36 | @Override 37 | public boolean getUseDeveloperSupport() { 38 | return BuildConfig.DEBUG; 39 | } 40 | 41 | @Override 42 | protected List getPackages() { 43 | @SuppressWarnings("UnnecessaryLocalVariable") 44 | List packages = new PackageList(this).getPackages(); 45 | // Packages that cannot be autolinked yet can be added manually here, for example: 46 | // packages.add(new MyReactNativePackage()); 47 | packages.add(new ReactNativeV8Package()); 48 | return packages; 49 | } 50 | 51 | @Override 52 | protected String getJSMainModuleName() { 53 | return "index"; 54 | } 55 | 56 | @Override 57 | protected String getBundleAssetName() { 58 | final String v8BundleAssetName = V8ExecutorFactory.getBundleAssetName(getApplicationContext(), getUseDeveloperSupport()); 59 | if (v8BundleAssetName != null) { 60 | return v8BundleAssetName; 61 | } 62 | return super.getBundleAssetName(); 63 | } 64 | 65 | @Override 66 | protected JavaScriptExecutorFactory getJavaScriptExecutorFactory() { 67 | 68 | return new V8ExecutorFactory( 69 | getApplicationContext(), 70 | getPackageName(), 71 | AndroidInfoHelpers.getFriendlyDeviceName(), 72 | getUseDeveloperSupport()); 73 | } 74 | }; 75 | 76 | private final ReactNativeHost mNewArchitectureNativeHost = 77 | new MainApplicationReactNativeHost(this); 78 | 79 | @Override 80 | public ReactNativeHost getReactNativeHost() { 81 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 82 | return mNewArchitectureNativeHost; 83 | } else { 84 | return mReactNativeHost; 85 | } 86 | } 87 | 88 | @Override 89 | public void onCreate() { 90 | super.onCreate(); 91 | ReactMarker.addListener(this); 92 | // If you opted-in for the New Architecture, we enable the TurboModule system 93 | ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 94 | SoLoader.init(this, /* native exopackage */ false); 95 | // initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); // Remove this line if you don't want Flipper enabled 96 | } 97 | 98 | /** 99 | * Loads Flipper in React Native templates. 100 | * 101 | * @param context 102 | */ 103 | private static void initializeFlipper( 104 | Context context, ReactInstanceManager reactInstanceManager) { 105 | if (BuildConfig.DEBUG) { 106 | try { 107 | /* 108 | We use reflection here to pick up the class that initializes Flipper, 109 | since Flipper library is not available in release mode 110 | */ 111 | Class aClass = Class.forName("com.facebook.flipper.ReactNativeFlipper"); 112 | aClass 113 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 114 | .invoke(null, context, reactInstanceManager); 115 | } catch (ClassNotFoundException e) { 116 | e.printStackTrace(); 117 | } catch (NoSuchMethodException e) { 118 | e.printStackTrace(); 119 | } catch (IllegalAccessException e) { 120 | e.printStackTrace(); 121 | } catch (InvocationTargetException e) { 122 | e.printStackTrace(); 123 | } 124 | } 125 | } 126 | 127 | @Override 128 | public void onTerminate() { 129 | ReactMarker.removeListener(this); 130 | super.onTerminate(); 131 | } 132 | 133 | // 134 | // ReactMarker.MarkerListener implementations 135 | // 136 | @Override 137 | public void logMarker(ReactMarkerConstants name, @Nullable String tag, int instanceKey) { 138 | if (name == ReactMarkerConstants.GET_REACT_INSTANCE_MANAGER_START) { 139 | mTTIStartTime = System.currentTimeMillis(); 140 | } else if (name == ReactMarkerConstants.CONTENT_APPEARED) { 141 | mTTIEndTime = System.currentTimeMillis(); 142 | Log.i("MeasureTTI", "TTI=" + (mTTIEndTime - mTTIStartTime)); 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /android/v8/src/main/java/com/rnbenchmark/newarchitecture/MainApplicationReactNativeHost.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture; 2 | 3 | import android.app.Application; 4 | import androidx.annotation.NonNull; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactInstanceManager; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 10 | import com.facebook.react.bridge.JSIModulePackage; 11 | import com.facebook.react.bridge.JSIModuleProvider; 12 | import com.facebook.react.bridge.JSIModuleSpec; 13 | import com.facebook.react.bridge.JSIModuleType; 14 | import com.facebook.react.bridge.JavaScriptContextHolder; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.UIManager; 17 | import com.facebook.react.fabric.ComponentFactory; 18 | import com.facebook.react.fabric.CoreComponentsRegistry; 19 | import com.facebook.react.fabric.EmptyReactNativeConfig; 20 | import com.facebook.react.fabric.FabricJSIModuleProvider; 21 | import com.facebook.react.uimanager.ViewManagerRegistry; 22 | import com.rnbenchmark.BuildConfig; 23 | import com.rnbenchmark.newarchitecture.components.MainComponentsRegistry; 24 | import com.rnbenchmark.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both 30 | * TurboModule delegates and the Fabric Renderer. 31 | * 32 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 33 | * `newArchEnabled` property). Is ignored otherwise. 34 | */ 35 | public class MainApplicationReactNativeHost extends ReactNativeHost { 36 | public MainApplicationReactNativeHost(Application application) { 37 | super(application); 38 | } 39 | 40 | @Override 41 | public boolean getUseDeveloperSupport() { 42 | return BuildConfig.DEBUG; 43 | } 44 | 45 | @Override 46 | protected List getPackages() { 47 | List packages = new PackageList(this).getPackages(); 48 | // Packages that cannot be autolinked yet can be added manually here, for example: 49 | // packages.add(new MyReactNativePackage()); 50 | // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: 51 | // packages.add(new TurboReactPackage() { ... }); 52 | // If you have custom Fabric Components, their ViewManagers should also be loaded here 53 | // inside a ReactPackage. 54 | return packages; 55 | } 56 | 57 | @Override 58 | protected String getJSMainModuleName() { 59 | return "index"; 60 | } 61 | 62 | @NonNull 63 | @Override 64 | protected ReactPackageTurboModuleManagerDelegate.Builder 65 | getReactPackageTurboModuleManagerDelegateBuilder() { 66 | // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary 67 | // for the new architecture and to use TurboModules correctly. 68 | return new MainApplicationTurboModuleManagerDelegate.Builder(); 69 | } 70 | 71 | @Override 72 | protected JSIModulePackage getJSIModulePackage() { 73 | return new JSIModulePackage() { 74 | @Override 75 | public List getJSIModules( 76 | final ReactApplicationContext reactApplicationContext, 77 | final JavaScriptContextHolder jsContext) { 78 | final List specs = new ArrayList<>(); 79 | 80 | // Here we provide a new JSIModuleSpec that will be responsible of providing the 81 | // custom Fabric Components. 82 | specs.add( 83 | new JSIModuleSpec() { 84 | @Override 85 | public JSIModuleType getJSIModuleType() { 86 | return JSIModuleType.UIManager; 87 | } 88 | 89 | @Override 90 | public JSIModuleProvider getJSIModuleProvider() { 91 | final ComponentFactory componentFactory = new ComponentFactory(); 92 | CoreComponentsRegistry.register(componentFactory); 93 | 94 | // Here we register a Components Registry. 95 | // The one that is generated with the template contains no components 96 | // and just provides you the one from React Native core. 97 | MainComponentsRegistry.register(componentFactory); 98 | 99 | final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); 100 | 101 | ViewManagerRegistry viewManagerRegistry = 102 | new ViewManagerRegistry( 103 | reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); 104 | 105 | return new FabricJSIModuleProvider( 106 | reactApplicationContext, 107 | componentFactory, 108 | new EmptyReactNativeConfig(), 109 | viewManagerRegistry); 110 | } 111 | }); 112 | return specs; 113 | } 114 | }; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /android/v8/src/main/java/com/rnbenchmark/newarchitecture/components/MainComponentsRegistry.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.components; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.proguard.annotations.DoNotStrip; 5 | import com.facebook.react.fabric.ComponentFactory; 6 | import com.facebook.soloader.SoLoader; 7 | 8 | /** 9 | * Class responsible to load the custom Fabric Components. This class has native methods and needs a 10 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 11 | * folder for you). 12 | * 13 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 14 | * `newArchEnabled` property). Is ignored otherwise. 15 | */ 16 | @DoNotStrip 17 | public class MainComponentsRegistry { 18 | static { 19 | SoLoader.loadLibrary("fabricjni"); 20 | } 21 | 22 | @DoNotStrip private final HybridData mHybridData; 23 | 24 | @DoNotStrip 25 | private native HybridData initHybrid(ComponentFactory componentFactory); 26 | 27 | @DoNotStrip 28 | private MainComponentsRegistry(ComponentFactory componentFactory) { 29 | mHybridData = initHybrid(componentFactory); 30 | } 31 | 32 | @DoNotStrip 33 | public static MainComponentsRegistry register(ComponentFactory componentFactory) { 34 | return new MainComponentsRegistry(componentFactory); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /android/v8/src/main/java/com/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package com.rnbenchmark.newarchitecture.modules; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.soloader.SoLoader; 8 | import java.util.List; 9 | 10 | /** 11 | * Class responsible to load the TurboModules. This class has native methods and needs a 12 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 13 | * folder for you). 14 | * 15 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 16 | * `newArchEnabled` property). Is ignored otherwise. 17 | */ 18 | public class MainApplicationTurboModuleManagerDelegate 19 | extends ReactPackageTurboModuleManagerDelegate { 20 | 21 | private static volatile boolean sIsSoLibraryLoaded; 22 | 23 | protected MainApplicationTurboModuleManagerDelegate( 24 | ReactApplicationContext reactApplicationContext, List packages) { 25 | super(reactApplicationContext, packages); 26 | } 27 | 28 | protected native HybridData initHybrid(); 29 | 30 | native boolean canCreateTurboModule(String moduleName); 31 | 32 | public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { 33 | protected MainApplicationTurboModuleManagerDelegate build( 34 | ReactApplicationContext context, List packages) { 35 | return new MainApplicationTurboModuleManagerDelegate(context, packages); 36 | } 37 | } 38 | 39 | @Override 40 | protected synchronized void maybeLoadOtherSoLibraries() { 41 | if (!sIsSoLibraryLoaded) { 42 | // If you change the name of your application .so file in the Android.mk file, 43 | // make sure you update the name here as well. 44 | SoLoader.loadLibrary("rnbenchmark_appmodules"); 45 | sIsSoLibraryLoaded = true; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | THIS_DIR := $(call my-dir) 2 | 3 | include $(REACT_ANDROID_DIR)/Android-prebuilt.mk 4 | 5 | # If you wish to add a custom TurboModule or Fabric component in your app you 6 | # will have to include the following autogenerated makefile. 7 | # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_PATH := $(THIS_DIR) 11 | 12 | # You can customize the name of your application .so file here. 13 | LOCAL_MODULE := rnbenchmark_appmodules 14 | 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 16 | LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) 17 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 18 | 19 | # If you wish to add a custom TurboModule or Fabric component in your app you 20 | # will have to uncomment those lines to include the generated source 21 | # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) 22 | # 23 | # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 24 | # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) 25 | # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 26 | 27 | # Here you should add any native library you wish to depend on. 28 | LOCAL_SHARED_LIBRARIES := \ 29 | libfabricjni \ 30 | libfbjni \ 31 | libfolly_futures \ 32 | libfolly_json \ 33 | libglog \ 34 | libjsi \ 35 | libreact_codegen_rncore \ 36 | libreact_debug \ 37 | libreact_nativemodule_core \ 38 | libreact_render_componentregistry \ 39 | libreact_render_core \ 40 | libreact_render_debug \ 41 | libreact_render_graphics \ 42 | librrc_view \ 43 | libruntimeexecutor \ 44 | libturbomodulejsijni \ 45 | libyoga 46 | 47 | LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall 48 | 49 | include $(BUILD_SHARED_LIBRARY) 50 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainApplicationModuleProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationModuleProvider.h" 2 | 3 | #include 4 | 5 | namespace facebook { 6 | namespace react { 7 | 8 | std::shared_ptr MainApplicationModuleProvider( 9 | const std::string moduleName, 10 | const JavaTurboModule::InitParams ¶ms) { 11 | // Here you can provide your own module provider for TurboModules coming from 12 | // either your application or from external libraries. The approach to follow 13 | // is similar to the following (for a library called `samplelibrary`: 14 | // 15 | // auto module = samplelibrary_ModuleProvider(moduleName, params); 16 | // if (module != nullptr) { 17 | // return module; 18 | // } 19 | // return rncore_ModuleProvider(moduleName, params); 20 | return rncore_ModuleProvider(moduleName, params); 21 | } 22 | 23 | } // namespace react 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainApplicationModuleProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | std::shared_ptr MainApplicationModuleProvider( 12 | const std::string moduleName, 13 | const JavaTurboModule::InitParams ¶ms); 14 | 15 | } // namespace react 16 | } // namespace facebook 17 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationTurboModuleManagerDelegate.h" 2 | #include "MainApplicationModuleProvider.h" 3 | 4 | namespace facebook { 5 | namespace react { 6 | 7 | jni::local_ref 8 | MainApplicationTurboModuleManagerDelegate::initHybrid( 9 | jni::alias_ref) { 10 | return makeCxxInstance(); 11 | } 12 | 13 | void MainApplicationTurboModuleManagerDelegate::registerNatives() { 14 | registerHybrid({ 15 | makeNativeMethod( 16 | "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), 17 | makeNativeMethod( 18 | "canCreateTurboModule", 19 | MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), 20 | }); 21 | } 22 | 23 | std::shared_ptr 24 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 25 | const std::string name, 26 | const std::shared_ptr jsInvoker) { 27 | // Not implemented yet: provide pure-C++ NativeModules here. 28 | return nullptr; 29 | } 30 | 31 | std::shared_ptr 32 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 33 | const std::string name, 34 | const JavaTurboModule::InitParams ¶ms) { 35 | return MainApplicationModuleProvider(name, params); 36 | } 37 | 38 | bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( 39 | std::string name) { 40 | return getTurboModule(name, nullptr) != nullptr || 41 | getTurboModule(name, {.moduleName = name}) != nullptr; 42 | } 43 | 44 | } // namespace react 45 | } // namespace facebook 46 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainApplicationTurboModuleManagerDelegate.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace facebook { 8 | namespace react { 9 | 10 | class MainApplicationTurboModuleManagerDelegate 11 | : public jni::HybridClass< 12 | MainApplicationTurboModuleManagerDelegate, 13 | TurboModuleManagerDelegate> { 14 | public: 15 | // Adapt it to the package you used for your Java class. 16 | static constexpr auto kJavaDescriptor = 17 | "Lcom/rnbenchmark/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; 18 | 19 | static jni::local_ref initHybrid(jni::alias_ref); 20 | 21 | static void registerNatives(); 22 | 23 | std::shared_ptr getTurboModule( 24 | const std::string name, 25 | const std::shared_ptr jsInvoker) override; 26 | std::shared_ptr getTurboModule( 27 | const std::string name, 28 | const JavaTurboModule::InitParams ¶ms) override; 29 | 30 | /** 31 | * Test-only method. Allows user to verify whether a TurboModule can be 32 | * created by instances of this class. 33 | */ 34 | bool canCreateTurboModule(std::string name); 35 | }; 36 | 37 | } // namespace react 38 | } // namespace facebook 39 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainComponentsRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "MainComponentsRegistry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} 12 | 13 | std::shared_ptr 14 | MainComponentsRegistry::sharedProviderRegistry() { 15 | auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); 16 | 17 | // Custom Fabric Components go here. You can register custom 18 | // components coming from your App or from 3rd party libraries here. 19 | // 20 | // providerRegistry->add(concreteComponentDescriptorProvider< 21 | // AocViewerComponentDescriptor>()); 22 | return providerRegistry; 23 | } 24 | 25 | jni::local_ref 26 | MainComponentsRegistry::initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate) { 29 | auto instance = makeCxxInstance(delegate); 30 | 31 | auto buildRegistryFunction = 32 | [](EventDispatcher::Weak const &eventDispatcher, 33 | ContextContainer::Shared const &contextContainer) 34 | -> ComponentDescriptorRegistry::Shared { 35 | auto registry = MainComponentsRegistry::sharedProviderRegistry() 36 | ->createComponentDescriptorRegistry( 37 | {eventDispatcher, contextContainer}); 38 | 39 | auto mutableRegistry = 40 | std::const_pointer_cast(registry); 41 | 42 | mutableRegistry->setFallbackComponentDescriptor( 43 | std::make_shared( 44 | ComponentDescriptorParameters{ 45 | eventDispatcher, contextContainer, nullptr})); 46 | 47 | return registry; 48 | }; 49 | 50 | delegate->buildRegistryFunction = buildRegistryFunction; 51 | return instance; 52 | } 53 | 54 | void MainComponentsRegistry::registerNatives() { 55 | registerHybrid({ 56 | makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), 57 | }); 58 | } 59 | 60 | } // namespace react 61 | } // namespace facebook 62 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/MainComponentsRegistry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | class MainComponentsRegistry 12 | : public facebook::jni::HybridClass { 13 | public: 14 | // Adapt it to the package you used for your Java class. 15 | constexpr static auto kJavaDescriptor = 16 | "Lcom/rnbenchmark/newarchitecture/components/MainComponentsRegistry;"; 17 | 18 | static void registerNatives(); 19 | 20 | MainComponentsRegistry(ComponentFactory *delegate); 21 | 22 | private: 23 | static std::shared_ptr 24 | sharedProviderRegistry(); 25 | 26 | static jni::local_ref initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate); 29 | }; 30 | 31 | } // namespace react 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /android/v8/src/main/jni/OnLoad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MainApplicationTurboModuleManagerDelegate.h" 3 | #include "MainComponentsRegistry.h" 4 | 5 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { 6 | return facebook::jni::initialize(vm, [] { 7 | facebook::react::MainApplicationTurboModuleManagerDelegate:: 8 | registerNatives(); 9 | facebook::react::MainComponentsRegistry::registerNatives(); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /android/v8/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/drawable-mdpi/node_modules_reactnative_libraries_newappscreen_components_logo.png -------------------------------------------------------------------------------- /android/v8/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /android/v8/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/android/v8/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /android/v8/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | RNBenchmark 3 | 4 | -------------------------------------------------------------------------------- /android/v8/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RNBenchmark", 3 | "displayName": "RNBenchmark" 4 | } -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import { AppRegistry } from 'react-native'; 6 | import App from './App'; 7 | import { name as appName } from './app.json'; 8 | 9 | AppRegistry.registerComponent(appName, () => App); 10 | -------------------------------------------------------------------------------- /js_dists.py: -------------------------------------------------------------------------------- 1 | JS_DISTS = { 2 | "jsc_250230": { 3 | "download_url": "https://registry.npmjs.org/jsc-android/-/jsc-android-250230.2.1.tgz", 4 | "version": "250230.2.1", 5 | "meta": ("Baseline JIT (but not x86)", "WebKitGTK 2.26.1"), 6 | "aar_glob": "**/android-jsc/**/*.aar", 7 | "binary_name": "libjsc.so", 8 | "maven_dist_path": "package/dist", 9 | "intl": False, 10 | }, 11 | "v8_100_jit": { 12 | "download_url": "https://registry.npmjs.org/v8-android-jit/-/v8-android-jit-10.100.0.tgz", 13 | "version": "10.100.0", 14 | "meta": ("JIT", "V8 10.0.139.9"), 15 | "aar_glob": "**/*.aar", 16 | "binary_name": "libv8android.so", 17 | "maven_dist_path": "package/dist", 18 | "intl": True, 19 | }, 20 | "v8_100_nointl": { 21 | "download_url": "https://registry.npmjs.org/v8-android-nointl/-/v8-android-nointl-10.100.0.tgz", 22 | "version": "10.100.0", 23 | "meta": ("V8 Light mode", "V8 10.0.139.9"), 24 | "aar_glob": "**/*.aar", 25 | "binary_name": "libv8android.so", 26 | "maven_dist_path": "package/dist", 27 | "intl": False, 28 | }, 29 | "hermes_0110": { 30 | "download_url": "https://registry.npmjs.org/hermes-engine/-/hermes-engine-0.11.0.tgz", 31 | "version": "0.11.0", 32 | "meta": ("JIT-less", "bytecode AOT"), 33 | "aar_glob": "**/android/hermes-release.aar", 34 | "binary_name": "libhermes.so", 35 | "maven_dist_path": "package/android", 36 | "intl": True, 37 | }, 38 | } 39 | -------------------------------------------------------------------------------- /lib/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Kudo/react-native-js-benchmark/4c7a858cf0085d124a627cbb40c33291a4ea618e/lib/__init__.py -------------------------------------------------------------------------------- /lib/colorful.py: -------------------------------------------------------------------------------- 1 | try: 2 | import colorful 3 | 4 | colorful.use_style("solarized") 5 | except ImportError: 6 | 7 | class NOPColorful: 8 | def __call__(self, s): 9 | return s 10 | 11 | def __getattr__(self, attr): 12 | return self 13 | 14 | colorful = NOPColorful() 15 | -------------------------------------------------------------------------------- /lib/logger.py: -------------------------------------------------------------------------------- 1 | import logging 2 | import sys 3 | from .colorful import colorful 4 | 5 | 6 | def setup_logger(verbose=False): 7 | handler = logging.StreamHandler(sys.stdout) 8 | 9 | class LevelFormatter(logging.Formatter): 10 | DEBUG_FORMATTER = logging.Formatter( 11 | str(colorful.italic_base01(" >>> [DEBUG] %(message)s")) 12 | ) 13 | 14 | def format(self, record): 15 | if record.levelno == logging.DEBUG: 16 | return self.DEBUG_FORMATTER.format(record) 17 | return super(LevelFormatter, self).format(record) 18 | 19 | handler.setFormatter(LevelFormatter()) 20 | root_logger = logging.getLogger() 21 | root_logger.addHandler(handler) 22 | if verbose: 23 | root_logger.setLevel(logging.DEBUG) 24 | else: 25 | root_logger.setLevel(logging.INFO) 26 | 27 | 28 | def get_logger(name): 29 | return logging.getLogger(name) 30 | -------------------------------------------------------------------------------- /lib/section.py: -------------------------------------------------------------------------------- 1 | from .colorful import colorful 2 | 3 | 4 | def h1(string): 5 | return ( 6 | "\n" 7 | + colorful.blue("#############################################\n") 8 | + colorful.blue("# ") 9 | + colorful.bold_yellow(string) 10 | + "\n" 11 | + colorful.blue("#############################################\n") 12 | ) 13 | 14 | 15 | def h2(string): 16 | return ( 17 | "\n" 18 | + colorful.base1("---------------------------------------------\n") 19 | + colorful.yellow(string) 20 | + "\n" 21 | + colorful.base1("---------------------------------------------\n") 22 | ) 23 | -------------------------------------------------------------------------------- /lib/tools.py: -------------------------------------------------------------------------------- 1 | import glob 2 | import io 3 | import os 4 | import re 5 | import shlex 6 | import subprocess 7 | from pathlib import Path 8 | from .logger import get_logger 9 | from .types import InstallProps 10 | 11 | logger = get_logger(__name__) 12 | 13 | 14 | class AdbTool: 15 | @classmethod 16 | def wait_for_log(cls, regex, tag): 17 | pattern = re.compile(tag + r": " + regex) 18 | cmd = ["adb", "logcat"] 19 | with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc: 20 | for line_in_bytes in iter(proc.stdout.readline, ""): 21 | line = line_in_bytes.decode("utf8") 22 | search = pattern.search(line) 23 | if search is not None: 24 | proc.terminate() 25 | return search 26 | 27 | @classmethod 28 | def wait_for_console_log(cls, regex): 29 | return cls.wait_for_log(regex, "ReactNativeJS") 30 | 31 | @classmethod 32 | def clear_log(cls): 33 | os.system("adb logcat -c") 34 | 35 | @classmethod 36 | def get_memory(cls, app_id): 37 | output = subprocess.check_output( 38 | ["adb", "shell", "dumpsys", "meminfo", "com.rnbenchmark.{}".format(app_id)] 39 | ).decode("utf8") 40 | 41 | with io.StringIO(output) as f: 42 | for line in f: 43 | if line.find("TOTAL") != -1: 44 | columns = line.split() 45 | if len(columns) >= 8: 46 | return columns[1] 47 | return -1 48 | 49 | @classmethod 50 | def stop_app(cls, app_id): 51 | os.system("adb shell am force-stop com.rnbenchmark.{}".format(app_id)) 52 | os.system("adb shell am kill com.rnbenchmark.{}".format(app_id)) 53 | 54 | @classmethod 55 | def stop_apps(cls): 56 | cls.stop_app("jsc") 57 | cls.stop_app("v8") 58 | cls.stop_app("hermes") 59 | 60 | @classmethod 61 | def start_with_link(cls, app_id, path_with_query): 62 | os.system( 63 | 'adb shell am start -a android.intent.action.VIEW -d "rnbench://{}{}"' 64 | " > /dev/null".format(app_id, path_with_query) 65 | ) 66 | 67 | 68 | class ApkTool: 69 | @classmethod 70 | def build( 71 | cls, 72 | app_id=None, 73 | maven_repo_prop=None, 74 | abi=None, 75 | verbose=False, 76 | extra_gradle_props=None, 77 | ): 78 | assert app_id 79 | assert maven_repo_prop 80 | 81 | os.chdir("android") 82 | gradle_prop = "" 83 | if verbose: 84 | gradle_prop += "-q " 85 | gradle_prop += "--project-prop " + maven_repo_prop 86 | if abi: 87 | gradle_prop += " --project-prop reactNativeArchitectures={}".format(abi) 88 | gradle_prop += " --project-prop ABI_BASED_APK=true" 89 | if extra_gradle_props: 90 | gradle_prop += " " 91 | prefixed_props = ("--project-prop " + p for p in extra_gradle_props) 92 | gradle_prop += " ".join(prefixed_props) 93 | cmd = "./gradlew {gradle_prop} \ 94 | :{app}:clean :{app}:assembleRelease".format( 95 | gradle_prop=gradle_prop, app=app_id 96 | ) 97 | logger.debug("build - cmd: {}".format(cmd)) 98 | stdout = subprocess.DEVNULL if not verbose else None 99 | stderr = subprocess.DEVNULL if not verbose else None 100 | subprocess.run(shlex.split(cmd), stdout=stdout, stderr=stderr) 101 | if abi: 102 | apk_file = "{app}/build/outputs/apk/release/{app}-{abi}-release.apk".format( 103 | app=app_id, abi=abi 104 | ) 105 | else: 106 | apk_file = "{app}/build/outputs/apk/release/{app}-release.apk".format( 107 | app=app_id 108 | ) 109 | apk_file = os.path.abspath(apk_file) 110 | os.chdir("../") 111 | return apk_file 112 | 113 | @classmethod 114 | def reinstall( 115 | cls, 116 | app_id=None, 117 | maven_repo_prop=None, 118 | abi=None, 119 | verbose=False, 120 | extra_gradle_props=None, 121 | ): 122 | assert app_id 123 | assert maven_repo_prop 124 | 125 | os.chdir("android") 126 | gradle_prop = "" 127 | if verbose: 128 | gradle_prop += "-q " 129 | gradle_prop += "--project-prop " + maven_repo_prop 130 | if abi: 131 | gradle_prop += " --project-prop reactNativeArchitectures={}".format(abi) 132 | gradle_prop += " --project-prop ABI_BASED_APK=true" 133 | if extra_gradle_props: 134 | gradle_prop += " " 135 | prefixed_props = ("--project-prop " + p for p in extra_gradle_props) 136 | gradle_prop += " ".join(prefixed_props) 137 | cmd = "./gradlew {gradle_prop} \ 138 | :{app}:clean :{app}:uninstallRelease :{app}:installRelease".format( 139 | gradle_prop=gradle_prop, app=app_id 140 | ) 141 | logger.debug("reinstall - cmd: {}".format(cmd)) 142 | stdout = subprocess.DEVNULL if not verbose else None 143 | stderr = subprocess.DEVNULL if not verbose else None 144 | subprocess.run(shlex.split(cmd), stdout=stdout, stderr=stderr) 145 | os.chdir("../") 146 | 147 | @classmethod 148 | def get_assets_size(cls, app_id): 149 | assets_dir = Path( 150 | "android/{}/build/intermediates/merged_assets/release/out".format(app_id) 151 | ) 152 | return sum(f.stat().st_size for f in assets_dir.glob("**/*") if f.is_file()) 153 | -------------------------------------------------------------------------------- /lib/types.py: -------------------------------------------------------------------------------- 1 | import typing 2 | 3 | 4 | class InstallProps(typing.TypedDict): 5 | app_id: str 6 | abi: str 7 | verbose: bool 8 | maven_repo_prop: str 9 | extra_gradle_props: list[str] 10 | -------------------------------------------------------------------------------- /metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: true, 14 | }, 15 | }), 16 | }, 17 | resolver: { 18 | blockList: [/\/js_dist\//], 19 | }, 20 | }; 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "RNBenchmark", 3 | "version": "0.0.2", 4 | "private": true, 5 | "scripts": { 6 | "android": "react-native run-android", 7 | "ios": "react-native run-ios", 8 | "start": "react-native start", 9 | "test": "jest", 10 | "lint": "eslint ." 11 | }, 12 | "dependencies": { 13 | "react": "17.0.2", 14 | "react-native": "0.68.1", 15 | "react-native-v8": "~1.1.0", 16 | "url-parse": "^1.5.9", 17 | "v8-android-jit": "^9.93.0" 18 | }, 19 | "devDependencies": { 20 | "@babel/core": "^7.12.9", 21 | "@babel/runtime": "^7.12.5", 22 | "@react-native-community/eslint-config": "^2.0.0", 23 | "babel-jest": "^26.6.3", 24 | "eslint": "^7.32.0", 25 | "jest": "^26.6.3", 26 | "metro-react-native-babel-preset": "^0.67.0", 27 | "react-test-renderer": "17.0.2", 28 | "v8-android-tools-macos": "^10.100.0" 29 | }, 30 | "jest": { 31 | "preset": "react-native" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /react-native.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | dependencies: { 3 | 'react-native-v8': { 4 | platforms: { 5 | android: null, // disable Android platform, other platforms will still autolink if provided 6 | }, 7 | }, 8 | }, 9 | }; 10 | -------------------------------------------------------------------------------- /src/ReactRender/RenderComponentMemory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import React, { useEffect, useLayoutEffect, useState, useRef } from 'react'; 6 | import { ScrollView, View, Text, StyleSheet } from 'react-native'; 7 | 8 | const Child = ({ id, onMount }) => { 9 | useLayoutEffect(() => { 10 | onMount(id); 11 | }, [id, onMount]); 12 | 13 | return ( 14 | 15 | {id} 16 | 17 | ); 18 | }; 19 | 20 | const RenderComponentMemory = ({ totalCount }) => { 21 | const [children, setChildren] = useState([0]); 22 | const [shouldContinue, setShouldContinue] = useState(true); 23 | const latestChildren = useRef(children); 24 | 25 | function appendChild(id) { 26 | setTimeout(() => setChildren(array => [...array, id]), 0); 27 | } 28 | 29 | function handleChildDidMount(id) { 30 | if (id >= totalCount) { 31 | setShouldContinue(false); 32 | console.log(`count=${latestChildren.current.length}`); 33 | return; 34 | } 35 | if (shouldContinue && id === children.length - 1) { 36 | appendChild(id + 1); 37 | } 38 | } 39 | 40 | useEffect(() => { 41 | latestChildren.current = children; 42 | }); 43 | 44 | return ( 45 | 46 | {children.map(i => ( 47 | 48 | ))} 49 | 50 | ); 51 | }; 52 | 53 | const styles = StyleSheet.create({ 54 | scrollView: { 55 | flex: 1, 56 | }, 57 | child: { 58 | alignSelf: 'center', 59 | width: 120, 60 | height: 16, 61 | marginVertical: 8, 62 | backgroundColor: 'lightblue', 63 | }, 64 | childText: { 65 | textAlign: 'center', 66 | }, 67 | }); 68 | 69 | export default RenderComponentMemory; 70 | -------------------------------------------------------------------------------- /src/ReactRender/RenderComponentThroughput.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import React, { useEffect, useLayoutEffect, useState, useRef } from 'react'; 6 | import { ScrollView, View, Text, StyleSheet } from 'react-native'; 7 | 8 | const Child = ({ id, onMount }) => { 9 | useLayoutEffect(() => { 10 | onMount(id); 11 | }, [id, onMount]); 12 | 13 | return ( 14 | 15 | {id} 16 | 17 | ); 18 | }; 19 | 20 | const RenderComponentThroughput = ({ interval }) => { 21 | const [children, setChildren] = useState([0]); 22 | const [shouldContinue, setShouldContinue] = useState(true); 23 | const latestChildren = useRef(children); 24 | 25 | function appendChild(id) { 26 | setTimeout(() => setChildren(array => [...array, id]), 0); 27 | } 28 | 29 | function handleChildDidMount(id) { 30 | if (shouldContinue && id === children.length - 1) { 31 | appendChild(id + 1); 32 | } 33 | } 34 | 35 | useEffect(() => { 36 | latestChildren.current = children; 37 | }); 38 | 39 | useEffect(() => { 40 | // eslint-disable-next-line no-bitwise 41 | const intervalInt = interval | 0; 42 | setTimeout(() => { 43 | setShouldContinue(false); 44 | console.log(`count=${latestChildren.current.length}`); 45 | }, intervalInt); 46 | }, [interval]); 47 | 48 | return ( 49 | 50 | {children.map(i => ( 51 | 52 | ))} 53 | 54 | ); 55 | }; 56 | 57 | const styles = StyleSheet.create({ 58 | scrollView: { 59 | flex: 1, 60 | }, 61 | child: { 62 | alignSelf: 'center', 63 | width: 120, 64 | height: 16, 65 | marginVertical: 8, 66 | backgroundColor: 'lightblue', 67 | }, 68 | childText: { 69 | textAlign: 'center', 70 | }, 71 | }); 72 | 73 | export default RenderComponentThroughput; 74 | -------------------------------------------------------------------------------- /src/TTI/TTIView.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | * @flow strict-local 4 | */ 5 | 6 | import React from 'react'; 7 | import {View, Text, StyleSheet} from 'react-native'; 8 | import data from './data.json'; 9 | 10 | const TTIView = () => ( 11 | 12 | TTIView 13 | Size: {data.size} 14 | 15 | ); 16 | 17 | const styles = StyleSheet.create({ 18 | container: { 19 | flex: 1, 20 | backgroundColor: 'rgb(40, 160, 192)', 21 | flexDirection: 'column', 22 | justifyContent: 'center', 23 | }, 24 | titleText: { 25 | color: 'rgb(255, 255, 255)', 26 | fontSize: 32, 27 | textAlign: 'center', 28 | }, 29 | sizeText: { 30 | color: 'rgb(255, 255, 255)', 31 | fontSize: 20, 32 | textAlign: 'center', 33 | }, 34 | }); 35 | 36 | export default TTIView; 37 | -------------------------------------------------------------------------------- /src/TTI/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "This file will be overwritten by start.py for TTI measurement" 3 | } 4 | -------------------------------------------------------------------------------- /website/.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /website/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | 14 | # production 15 | /build 16 | 17 | # misc 18 | .DS_Store 19 | *.pem 20 | 21 | # debug 22 | npm-debug.log* 23 | yarn-debug.log* 24 | yarn-error.log* 25 | .pnpm-debug.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | -------------------------------------------------------------------------------- /website/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "bracketSameLine": true, 6 | "trailingComma": "es5" 7 | } 8 | -------------------------------------------------------------------------------- /website/README.md: -------------------------------------------------------------------------------- 1 | # Benchmark Result 2 | [https://kudo.github.io/react-native-js-benchmark](https://kudo.github.io/react-native-js-benchmark) 3 | -------------------------------------------------------------------------------- /website/components/Chart.tsx: -------------------------------------------------------------------------------- 1 | import { 2 | Chart as ChartJS, 3 | CategoryScale, 4 | LinearScale, 5 | BarElement, 6 | Title, 7 | Tooltip, 8 | Legend, 9 | } from 'chart.js'; 10 | import { Bar } from 'react-chartjs-2'; 11 | 12 | import styles from '../styles/Chart.module.css'; 13 | import type { ChartData } from '../types'; 14 | 15 | ChartJS.register(CategoryScale, LinearScale, BarElement, Title, Tooltip, Legend); 16 | 17 | const COLOR_PALETTE = { 18 | jsc: ['#ffca3a', '#ffa33a', '#ffb03a', '#ffbd3a', '#ffd73a', '#ffe43a'], 19 | v8: ['#8ac926', '#5e891a', '#ade05b', '#6d9e1e', '#a2dc46', '#7bb422'], 20 | hermes: ['#1982c4', '#19a4c4', '#1999ca', '#198dc4', '#1971c4', '#1966c4'], 21 | }; 22 | 23 | const COLOR_BUCKETS: Record = {}; 24 | 25 | function getBackgroundColor(jsEngine: string): string | undefined { 26 | if (COLOR_BUCKETS[jsEngine] != null) { 27 | return COLOR_BUCKETS[jsEngine]; 28 | } 29 | 30 | let result: string | undefined = undefined; 31 | if (jsEngine.startsWith('jsc')) { 32 | result = COLOR_PALETTE.jsc.pop(); 33 | } else if (jsEngine.startsWith('v8')) { 34 | result = COLOR_PALETTE.v8.pop(); 35 | } else if (jsEngine.startsWith('hermes')) { 36 | result = COLOR_PALETTE.hermes.pop(); 37 | } 38 | if (result === undefined) { 39 | result = '#b726c9'; 40 | } 41 | 42 | COLOR_BUCKETS[jsEngine] = result; 43 | return result; 44 | } 45 | 46 | export interface Props { 47 | data: ChartData; 48 | } 49 | 50 | export default function ChartWithSection(props: Props) { 51 | const options = { 52 | responsive: true, 53 | plugins: { 54 | legend: { 55 | position: 'top' as const, 56 | labels: { 57 | font: { 58 | size: 18, 59 | }, 60 | }, 61 | }, 62 | }, 63 | }; 64 | 65 | const data = { 66 | labels: props.data.testGroups, 67 | datasets: props.data.dataSet.map((data) => ({ 68 | label: data.jsEngine, 69 | data: data.groupData, 70 | backgroundColor: getBackgroundColor(data.jsEngine), 71 | })), 72 | }; 73 | 74 | return ; 75 | } 76 | -------------------------------------------------------------------------------- /website/env-config.js: -------------------------------------------------------------------------------- 1 | const prod = process.env.NODE_ENV === 'production' 2 | 3 | module.exports = { 4 | 'process.env.BACKEND_URL': prod ? '/react-native-js-benchmark' : '', 5 | } 6 | -------------------------------------------------------------------------------- /website/next-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | 4 | // NOTE: This file should not be edited 5 | // see https://nextjs.org/docs/basic-features/typescript for more information. 6 | -------------------------------------------------------------------------------- /website/next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const debug = process.env.NODE_ENV !== 'production' 3 | 4 | const nextConfig = { 5 | reactStrictMode: true, 6 | assetPrefix: !debug ? '/react-native-js-benchmark/' : '', 7 | } 8 | 9 | module.exports = nextConfig 10 | -------------------------------------------------------------------------------- /website/out/404.html: -------------------------------------------------------------------------------- 1 | 404: This page could not be found

404

This page could not be found.

-------------------------------------------------------------------------------- /website/out/_next/static/chunks/pages/_app-85d7488a393e293e.js: -------------------------------------------------------------------------------- 1 | (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[888],{6363:function(n,e,t){(window.__NEXT_P=window.__NEXT_P||[]).push(["/_app",function(){return t(3847)}])},3847:function(n,e,t){"use strict";t.r(e);var r=t(5893);t(6774);function u(n,e,t){return e in n?Object.defineProperty(n,e,{value:t,enumerable:!0,configurable:!0,writable:!0}):n[e]=t,n}e.default=function(n){var e=n.Component,t=n.pageProps;return(0,r.jsx)(e,function(n){for(var e=1;e=u)&&Object.keys(r.O).every((function(e){return r.O[e](t[a])}))?t.splice(a--,1):(f=!1,u0&&e[l-1][2]>u;l--)e[l]=e[l-1];e[l]=[t,o,u]}}(),r.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(n,{a:n}),n},r.d=function(e,n){for(var t in n)r.o(n,t)&&!r.o(e,t)&&Object.defineProperty(e,t,{enumerable:!0,get:n[t]})},r.o=function(e,n){return Object.prototype.hasOwnProperty.call(e,n)},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.p="/react-native-js-benchmark//_next/",function(){var e={272:0};r.O.j=function(n){return 0===e[n]};var n=function(n,t){var o,u,i=t[0],f=t[1],a=t[2],c=0;if(i.some((function(n){return 0!==e[n]}))){for(o in f)r.o(f,o)&&(r.m[o]=f[o]);if(a)var l=a(r)}for(n&&n(t);creact-native-js-benchmark

react-native-js-benchmark

React Native benchmark for JavaScript runtimes.

Measurement Information

RenderComponentThroughput

Aims at the computing performance (higher is better)


TTI

Aims at the app startup Time-To-Interactive (lower is better)

// TODO: Add asset size
-------------------------------------------------------------------------------- /website/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "website", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint", 10 | "deploy": "export NODE_ENV=production && rimraf node_modules/.cache && rimraf out && next build && next export && touch out/.nojekyll && git add out/ && git commit -m \"Deploy website to gh-pages\" && cd .. && git subtree push --prefix website/out origin gh-pages" 11 | }, 12 | "dependencies": { 13 | "chart.js": "^3.7.1", 14 | "next": "12.1.5", 15 | "react": "18.0.0", 16 | "react-chartjs-2": "^4.1.0", 17 | "react-dom": "18.0.0" 18 | }, 19 | "devDependencies": { 20 | "@types/chart.js": "^2.9.36", 21 | "@types/node": "17.0.25", 22 | "@types/react": "18.0.5", 23 | "@types/react-chartjs-2": "^2.5.7", 24 | "@types/react-dom": "18.0.1", 25 | "eslint": "8.13.0", 26 | "eslint-config-next": "12.1.5", 27 | "rimraf": "^3.0.2", 28 | "typescript": "4.6.3" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /website/pages/_app.tsx: -------------------------------------------------------------------------------- 1 | import '../styles/globals.css' 2 | import type { AppProps } from 'next/app' 3 | 4 | function MyApp({ Component, pageProps }: AppProps) { 5 | return 6 | } 7 | 8 | export default MyApp 9 | -------------------------------------------------------------------------------- /website/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import type { NextPage } from 'next'; 2 | import Head from 'next/head'; 3 | import styles from '../styles/Home.module.css'; 4 | import Chart from '../components/Chart'; 5 | import Data from '../public/data.json'; 6 | 7 | import type { ChartData } from '../types'; 8 | 9 | interface SectionProps { 10 | name: string; 11 | description: string; 12 | chartData: ChartData; 13 | } 14 | function Section(props: SectionProps) { 15 | return ( 16 |
17 |

18 | 19 | {props.name} 20 | 21 |

22 |

{props.description}

23 | 24 | {props.chartData.comment ? ( 25 | {props.chartData.comment} 26 | ) : null} 27 |
28 | ); 29 | } 30 | 31 | const Home: NextPage = () => { 32 | return ( 33 |
34 | 35 | react-native-js-benchmark 36 | 37 | 41 | 42 | 43 |
44 |

45 | react-native-js-benchmark 46 |

47 |

React Native benchmark for JavaScript runtimes.

48 | 49 |
50 |

Measurement Information

51 | 79 |
80 | 81 |
86 | 87 |
88 | 89 |
94 | 95 |
96 | 97 |
102 | 103 |
104 | 105 |
110 | 111 |
112 |
113 | ); 114 | }; 115 | 116 | export default Home; 117 | -------------------------------------------------------------------------------- /website/public/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "RenderComponentThroughput": { 3 | "testGroups": ["10s", "20s", "180s"], 4 | "dataSet": [ 5 | { 6 | "jsEngine": "jsc", 7 | "groupData": [612, 1776, 3130] 8 | }, 9 | { 10 | "jsEngine": "v8-android-jit", 11 | "groupData": [1057, 2794, 4638] 12 | }, 13 | { 14 | "jsEngine": "v8-android-nointl", 15 | "groupData": [470, 1338, 2209] 16 | }, 17 | { 18 | "jsEngine": "hermes", 19 | "groupData": [419, 1105, 1915] 20 | } 21 | ] 22 | }, 23 | 24 | "RenderComponentMemory": { 25 | "testGroups": ["100 items", "1000 items", "3000 items"], 26 | "dataSet": [ 27 | { 28 | "jsEngine": "jsc", 29 | "groupData": [108856, 253693, 289987] 30 | }, 31 | { 32 | "jsEngine": "v8-android-jit", 33 | "groupData": [123676, 172950, 323242] 34 | }, 35 | { 36 | "jsEngine": "v8-android-nointl", 37 | "groupData": [114076, 167940, 256979] 38 | }, 39 | { 40 | "jsEngine": "hermes", 41 | "groupData": [93594, 148041, 263733] 42 | } 43 | ] 44 | }, 45 | 46 | "TTI": { 47 | "testGroups": ["3MB bundle", "10MB bundle", "15MB bundle"], 48 | "dataSet": [ 49 | { 50 | "jsEngine": "jsc", 51 | "groupData": [125, 201, 295] 52 | }, 53 | { 54 | "jsEngine": "v8-android-jit", 55 | "groupData": [130, 193, 271] 56 | }, 57 | { 58 | "jsEngine": "v8-android-nointl", 59 | "groupData": [135, 194, 248] 60 | }, 61 | { 62 | "jsEngine": "v8-android-jit + normal cache", 63 | "groupData": [99, 145, 205] 64 | }, 65 | { 66 | "jsEngine": "v8-android-jit + prebuilt cache", 67 | "groupData": [82, 121, 144] 68 | }, 69 | { 70 | "jsEngine": "v8-android-jit + normal with stub cache", 71 | "groupData": [89, 138, 156] 72 | }, 73 | { 74 | "jsEngine": "hermes", 75 | "groupData": [72, 113, 151] 76 | } 77 | ] 78 | }, 79 | 80 | "ApkSize": { 81 | "testGroups": ["universal build (MB)"], 82 | "dataSet": [ 83 | { 84 | "jsEngine": "jsc", 85 | "groupData": [26.68] 86 | }, 87 | { 88 | "jsEngine": "v8-android-jit", 89 | "groupData": [50.71] 90 | }, 91 | { 92 | "jsEngine": "v8-android-nointl", 93 | "groupData": [34.46] 94 | }, 95 | { 96 | "jsEngine": "hermes", 97 | "groupData": [20.19] 98 | } 99 | ] 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /website/styles/Chart.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | width: 50vw; 3 | } 4 | -------------------------------------------------------------------------------- /website/styles/Home.module.css: -------------------------------------------------------------------------------- 1 | .container { 2 | padding: 0 2rem; 3 | } 4 | 5 | .main { 6 | min-height: 100vh; 7 | width: 60vw; 8 | margin: 0 auto; 9 | padding: 4rem 0; 10 | flex: 1; 11 | display: flex; 12 | flex-direction: column; 13 | justify-content: center; 14 | } 15 | 16 | .title a { 17 | color: #0070f3; 18 | text-decoration: none; 19 | } 20 | 21 | .title a:hover, 22 | .title a:focus, 23 | .title a:active { 24 | text-decoration: underline; 25 | } 26 | 27 | .title { 28 | margin: 0; 29 | line-height: 1.15; 30 | font-size: 4rem; 31 | } 32 | 33 | .title, 34 | .description { 35 | text-align: center; 36 | } 37 | 38 | .description { 39 | margin: 4rem 0; 40 | line-height: 1.5; 41 | font-size: 1.5rem; 42 | } 43 | 44 | .measureInfo { 45 | align-self: flex-start; 46 | margin: 2rem 0; 47 | } 48 | 49 | .measureInfo li { 50 | font-size: 1.25rem; 51 | line-height: 1.75; 52 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 53 | Bitstream Vera Sans Mono, Courier New, monospace; 54 | } 55 | 56 | .measureInfo li a { 57 | text-decoration: underline; 58 | } 59 | .sectionTitle { 60 | position: relative; 61 | } 62 | 63 | .sectionTitle::before { 64 | position: absolute; 65 | top: 0; 66 | left: -20px; 67 | height: 100%; 68 | } 69 | 70 | .sectionTitle:hover::before { 71 | content: '﹟'; 72 | cursor: pointer; 73 | } 74 | 75 | .sectionAnchor { 76 | display: block; 77 | } 78 | 79 | .divider { 80 | border-top: 1px solid #ccc; 81 | width: 50%; 82 | margin: 1.5rem; 83 | } 84 | 85 | .comment { 86 | display: block; 87 | margin: 1.5rem 0; 88 | background: #ededed; 89 | color: #333; 90 | border-radius: 5px; 91 | padding: 0.75rem; 92 | font-family: Menlo, Monaco, Lucida Console, Liberation Mono, DejaVu Sans Mono, 93 | Bitstream Vera Sans Mono, Courier New, monospace; 94 | } 95 | -------------------------------------------------------------------------------- /website/styles/globals.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Oxygen, Ubuntu, Cantarell, 6 | Fira Sans, Droid Sans, Helvetica Neue, sans-serif; 7 | } 8 | 9 | a { 10 | color: inherit; 11 | text-decoration: none; 12 | } 13 | 14 | * { 15 | box-sizing: border-box; 16 | } 17 | -------------------------------------------------------------------------------- /website/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "forceConsistentCasingInFileNames": true, 9 | "noEmit": true, 10 | "esModuleInterop": true, 11 | "module": "esnext", 12 | "moduleResolution": "node", 13 | "resolveJsonModule": true, 14 | "isolatedModules": true, 15 | "jsx": "preserve", 16 | "incremental": true 17 | }, 18 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"], 19 | "exclude": ["node_modules"] 20 | } 21 | -------------------------------------------------------------------------------- /website/types/index.ts: -------------------------------------------------------------------------------- 1 | export interface ChartData { 2 | testGroups: string[]; 3 | dataSet: ChartDataGroupSet[]; 4 | comment?: string; 5 | } 6 | 7 | export interface ChartDataGroupSet { 8 | jsEngine: string; 9 | groupData: string[] | number[]; 10 | } 11 | --------------------------------------------------------------------------------