invertase / react-native-firebase

πŸ”₯ A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.66k stars 2.21k forks source link

[πŸ›] [Android] - performance issue with v6 functions vs v5 #4200

Closed pmakwanaPresentation closed 3 years ago

pmakwanaPresentation commented 4 years ago

Issue

The android app is getting slow after using react-native-firebase v6 packages.

Before using react-native-firebase v6, we were using the firebase package and our API call was finishing within 4-5 sec, but after using react native-firebase v6 (@react-native-firebase/functions), it is taking 15 to 20 sec to fetch data and loading at UI with the same response.

I also tried using the latest versions for all firebase libs and overriding the BOM version to 25.3.1, but it's not helping.

Could anyone please guide me on this?

Thanks in advance!


Project Files

Javascript

Click To Expand

#### `package.json`: ```json { "name": "AppName", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@invertase/react-native-apple-authentication": "1.1.2", "@react-native-community/async-storage": "1.5.0", "@react-native-community/datetimepicker": "2.6.0", "@react-native-community/google-signin": "4.0.3", "@react-native-community/netinfo": "5.9.4", "@react-native-community/viewpager": "4.1.0", "@react-native-firebase/analytics": "7.3.1", "@react-native-firebase/app": "8.2.0", "@react-native-firebase/auth": "8.2.0", "@react-native-firebase/crashlytics": "8.1.2", "@react-native-firebase/database": "7.3.2", "@react-native-firebase/firestore": "7.4.3", "@react-native-firebase/functions": "7.2.2", "@react-native-firebase/messaging": "7.4.2", "@remobile/react-native-image-compress": "1.0.2", "@skele/components": "1.0.0-alpha.40", "@ungap/url-search-params": "0.1.2", "axios": "0.19.2", "base-64": "0.1.0", "firebase": "7.10.0", "firesql": "2.0.2", "intl": "1.2.5", "libphonenumber-js": "1.7.54", "link-preview-js": "1.4.3", "linq2fire": "1.0.22", "react": "16.11.0", "react-intl": "2.9.0", "react-native": "0.62.2", "react-native-android-keyboard-adjust": "1.2.0", "react-native-android-open-settings": "1.3.0", "react-native-animatable": "1.3.3", "react-native-calendar-picker": "6.0.1", "react-native-check-box": "2.1.7", "react-native-contacts": "5.0.3", "react-native-country-picker-modal": "1.10.0", "react-native-customized-image-picker": "0.1.11", "react-native-easy-toast": "1.2.0", "react-native-elements": "2.0.0", "react-native-fast-image": "8.3.2", "react-native-fbsdk": "1.0.1", "react-native-flash-message": "0.1.15", "react-native-gesture-handler": "1.5.0", "react-native-gifted-chat": "0.5.0", "react-native-image-pan-zoom": "2.1.12", "react-native-image-picker": "0.28.1", "react-native-image-resizer": "1.2.6", "react-native-instagram-login": "2.0.0", "react-native-keyboard-aware-scroll-view": "0.8.0", "react-native-linear-gradient": "2.5.6", "react-native-material-ripple": "0.9.1", "react-native-modal-datetime-picker": "8.6.0", "react-native-month-selector": "1.4.0", "react-native-optimized-flatlist": "1.0.4", "react-native-options-menu": "2.0.2", "react-native-parallax-scroll-view": "0.21.3", "react-native-permissions": "1.2.0", "react-native-receive-sharing-intent": "1.0.4", "react-native-restart": "0.0.15", "react-native-share": "1.2.1", "react-native-super-grid": "3.1.2", "react-native-svg": "9.5.1", "react-native-swipe-gestures": "1.0.3", "react-native-swipe-navigation": "1.0.0-beta", "react-native-swiper": "1.5.14", "react-native-vector-icons": "6.6.0", "react-native-version-number": "0.3.6", "react-native-video": "5.0.0", "react-native-walkthrough-tooltip": "0.6.1", "react-native-webview": "7.6.0", "react-navigation": "3.11.0", "react-redux": "5.0.6", "recyclerlistview": "2.0.12", "redux": "3.7.2", "rn-fetch-blob": "0.12.0", "rxfire": "3.6.10", "rxjs": "6.5.2", "styled-components": "4.3.2" }, "devDependencies": { "@babel/core": "^7.6.2", "@babel/runtime": "^7.6.2", "@react-native-community/eslint-config": "^0.0.5", "babel-jest": "^24.9.0", "eslint": "^6.5.1", "jest": "^24.9.0", "metro-react-native-babel-preset": "^0.58.0", "react-test-renderer": "16.11.0" }, "jest": { "preset": "react-native" } } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ```

iOS

Click To Expand

#### `ios/Podfile`: - [ ] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [x] my application is an AndroidX application? - [x] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [x] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext { buildToolsVersion = "28.0.3" minSdkVersion = 16 compileSdkVersion = 28 targetSdkVersion = 28 androidXCore = "1.0.2" } repositories { google() jcenter() } dependencies { classpath("com.android.tools.build:gradle:3.5.2") classpath("com.google.gms:google-services:4.2.0") classpath ('com.google.firebase:firebase-crashlytics-gradle:2.2.0') // Crashlytics plugin // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { mavenCentral() mavenLocal() google() jcenter() maven { url("$rootDir/../node_modules/react-native/android") } maven { url "https://jitpack.io" } maven { url "https://maven.google.com" } maven { url("$rootDir/../node_modules/jsc-android/dist") } } } // override every sub project on node module and replace build version with root version. subprojects { afterEvaluate {project -> if (project.hasProperty("android")) { android { compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion } } } } ``` #### `android/app/build.gradle`: ```groovy apply plugin: "com.android.application" apply plugin: 'com.google.firebase.crashlytics' import com.android.build.OutputFile /** * The react.gradle file registers a task for each build variant (e.g. bundleDebugJsAndAssets * and bundleReleaseJsAndAssets). * These basically call `react-native bundle` with the correct arguments during the Android build * cycle. By default, bundleDebugJsAndAssets is skipped, as in debug/dev mode we prefer to load the * bundle directly from the development server. Below you can see all the possible configurations * and their defaults. If you decide to add a configuration block, make sure to add it before the * `apply from: "../../node_modules/react-native/react.gradle"` line. * * project.ext.react = [ * // the name of the generated asset file containing your JS bundle * bundleAssetName: "index.android.bundle", * * // the entry file for bundle generation * entryFile: "index.android.js", * * // whether to bundle JS and assets in debug mode * bundleInDebug: false, * * // whether to bundle JS and assets in release mode * bundleInRelease: true, * * // whether to bundle JS and assets in another build variant (if configured). * // See http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants * // The configuration property can be in the following formats * // 'bundleIn${productFlavor}${buildType}' * // 'bundleIn${buildType}' * // bundleInFreeDebug: true, * // bundleInPaidRelease: true, * // bundleInBeta: true, * * // whether to disable dev mode in custom build variants (by default only disabled in release) * // for example: to disable dev mode in the staging build type (if configured) * devDisabledInStaging: true, * // The configuration property can be in the following formats * // 'devDisabledIn${productFlavor}${buildType}' * // 'devDisabledIn${buildType}' * * // the root of your project, i.e. where "package.json" lives * root: "../../", * * // where to put the JS bundle asset in debug mode * jsBundleDirDebug: "$buildDir/intermediates/assets/debug", * * // where to put the JS bundle asset in release mode * jsBundleDirRelease: "$buildDir/intermediates/assets/release", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in debug mode * resourcesDirDebug: "$buildDir/intermediates/res/merged/debug", * * // where to put drawable resources / React Native assets, e.g. the ones you use via * // require('./image.png')), in release mode * resourcesDirRelease: "$buildDir/intermediates/res/merged/release", * * // by default the gradle tasks are skipped if none of the JS files or assets change; this means * // that we don't look at files in android/ or ios/ to determine whether the tasks are up to * // date; if you have any other folders that you want to ignore for performance reasons (gradle * // indexes the entire tree), add them here. Alternatively, if you have JS files in android/ * // for example, you might want to remove it from here. * inputExcludes: ["android/**", "ios/**"], * * // override which node gets called and with what additional arguments * nodeExecutableAndArgs: ["node"], * * // supply additional arguments to the packager * extraPackagerArgs: [] * ] */ project.ext.react = [ entryFile: "index.js", enableHermes: true, ] apply from: "../../node_modules/react-native/react.gradle" /** * Set this to true to create two separate APKs instead of one: * - An APK that only works on ARM devices * - An APK that only works on x86 devices * The advantage is the size of the APK is reduced by about 4MB. * Upload all the APKs to the Play Store and people will download * the correct one based on the CPU architecture of their device. */ def enableSeparateBuildPerCPUArchitecture = false /** * Run Proguard to shrink the Java bytecode in release builds. */ def enableProguardInReleaseBuilds = false /** * The preferred build flavor of JavaScriptCore. * * For example, to use the international variant, you can use: * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` * * The international variant includes ICU i18n library and necessary data * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that * give correct results when using with locales other than en-US. Note that * this variant is about 6MiB larger per architecture than default. */ def jscFlavor = 'org.webkit:android-jsc:+' /** * Whether to enable the Hermes VM. * * This should be set on project.ext.react and mirrored here. If it is not set * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode * and the benefits of using Hermes will therefore be sharply reduced. */ def enableHermes = project.ext.react.get("enableHermes", false); android { compileSdkVersion rootProject.ext.compileSdkVersion compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } defaultConfig { ndk { abiFilters "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } multiDexEnabled = true applicationId "" minSdkVersion rootProject.ext.minSdkVersion targetSdkVersion rootProject.ext.targetSdkVersion versionCode 8 versionName "2.1.0" } signingConfigs { release { storeFile file(MYAPP_RELEASE_STORE_FILE) storePassword MYAPP_RELEASE_STORE_PASSWORD keyAlias MYAPP_RELEASE_KEY_ALIAS keyPassword MYAPP_RELEASE_KEY_PASSWORD } } splits { abi { reset() enable enableSeparateBuildPerCPUArchitecture universalApk false // If true, also generate a universal APK include "armeabi-v7a", "x86", "arm64-v8a", "x86_64" } } buildTypes { release { minifyEnabled enableProguardInReleaseBuilds proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro" signingConfig signingConfigs.release } } packagingOptions { pickFirst "lib/armeabi-v7a/libc++_shared.so" pickFirst "lib/arm64-v8a/libc++_shared.so" pickFirst "lib/x86/libc++_shared.so" pickFirst "lib/x86_64/libc++_shared.so" } // applicationVariants are e.g. debug, release applicationVariants.all { variant -> variant.outputs.each { output -> //Updating apk file name with version details def apkFileName = "app-${output.baseName}-${variant.versionName}_${variant.versionCode}.apk"; output.outputFileName = apkFileName; // For each separate APK per architecture, set a unique version code as described here: // http://tools.android.com/tech-docs/new-build-system/user-guide/apk-splits def versionCodes = ["armeabi-v7a": 1, "x86": 2, "arm64-v8a": 3, "x86_64": 4] def abi = output.getFilter(OutputFile.ABI) if (abi != null) { // null for the universal-debug, universal-release variants output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } } } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) // implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}" implementation "com.facebook.react:react-native:0.62.2" // From node_modules implementation "com.google.firebase:firebase-core:16.0.9" implementation "com.google.firebase:firebase-auth:17.0.0" implementation "com.google.android.gms:play-services-auth:16.0.1" implementation "com.google.firebase:firebase-functions:17.0.0" implementation "com.google.firebase:firebase-messaging:18.0.0" implementation "me.leolin:ShortcutBadger:1.1.21@aar" implementation "com.google.firebase:firebase-crashlytics:17.2.1" implementation "com.facebook.android:facebook-core:5.0.0" implementation "com.google.firebase:firebase-analytics:16.0.5" // For animated GIF support compile 'com.facebook.fresco:fresco:1.+' // For animated GIF support compile 'com.facebook.fresco:animated-gif:1.+' // For WebP support, including animated WebP compile 'com.facebook.fresco:animated-webp:1.+' compile 'com.facebook.fresco:webpsupport:1.+' if (enableHermes) { def hermesPath = "../../node_modules/hermes-engine/android/"; debugImplementation files(hermesPath + "hermes-debug.aar") releaseImplementation files(hermesPath + "hermes-release.aar") } else { implementation jscFlavor } } // Run this once to be able to run the application with BUCK // puts all compile dependencies into folder libs for BUCK to use task copyDownloadableDepsToLibs(type: Copy) { from configurations.compile into 'libs' } apply from: file("../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesAppBuildGradle(project) apply plugin: 'com.google.gms.google-services' apply from: "../../node_modules/react-native-vector-icons/fonts.gradle" ``` #### `android/settings.gradle`: ```groovy rootProject.name = 'name' include ':react-native-fast-image' project(':react-native-fast-image').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fast-image/android') apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) include ':app' ``` #### `MainApplication.java`: ```java package com.company.project; import android.app.Application; import com.facebook.react.ReactApplication; import com.dylanvann.fastimage.FastImageViewPackage; import com.reactnativecommunity.netinfo.NetInfoPackage; import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.soloader.SoLoader; import com.facebook.FacebookSdk; import com.facebook.CallbackManager; import com.facebook.appevents.AppEventsLogger; import java.lang.reflect.InvocationTargetException; import android.content.Context; import com.facebook.react.PackageList; import com.facebook.react.ReactInstanceManager; import java.util.Arrays; import java.util.List; import android.content.Intent; import com.google.firebase.crashlytics.FirebaseCrashlytics; public class MainApplication extends Application implements ReactApplication { private static CallbackManager mCallbackManager = CallbackManager.Factory.create(); protected static CallbackManager getCallbackManager() { return mCallbackManager; } private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) { @Override public boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List getPackages() { @SuppressWarnings("UnnecessaryLocalVariable") List packages = new PackageList(this).getPackages(); // Packages that cannot be autolinked yet can be added manually here, for example: packages.add(new CacheClearServicePackage()); return packages; } @Override protected String getJSMainModuleName() { return "index"; } }; @Override public ReactNativeHost getReactNativeHost() { return mReactNativeHost; } @Override public void onCreate() { super.onCreate(); Thread.setDefaultUncaughtExceptionHandler( new Thread.UncaughtExceptionHandler() { @Override public void uncaughtException(Thread thread, Throwable e) { FirebaseCrashlytics crashlytics = FirebaseCrashlytics.getInstance(); crashlytics.recordException(e); handleUncaughtException(thread, e); } } ); SoLoader.init(this, /* native exopackage */false); } public void handleUncaughtException(Thread thread, Throwable e) { e.printStackTrace(); // not all Android versions will print the stack trace automatically Intent intent = new Intent(); intent.setAction("com.company.project"); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); // required when starting from Application startActivity(intent); System.exit(1); // kill off the crashed app } } ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: Linux 4.15 Ubuntu 16.04.3 LTS (Xenial Xerus) CPU: (4) x64 Intel(R) Core(TM) i5-4440 CPU @ 3.10GHz Memory: 994.89 MB / 15.54 GB Shell: 4.3.48 - /bin/bash Binaries: Node: 12.2.0 - ~/.nvm/versions/node/v12.2.0/bin/node Yarn: 1.17.3 - ~/.nvm/versions/node/v12.2.0/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v12.2.0/bin/npm Watchman: Not Found SDKs: Android SDK: API Levels: 23, 26, 27, 28, 29 Build Tools: 23.0.1, 25.0.3, 26.0.2, 27.0.3, 28.0.3, 29.0.2 System Images: android-22 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom Android NDK: Not Found IDEs: Android Studio: Not Found Languages: Java: 1.8.0_265 - /usr/bin/javac Python: 2.7.12 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.2 => 0.62.2 npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [ ] iOS - [ ] Android - [ ] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `e.g. 5.4.3` - **`Firebase` module(s) you're using that has the issue:** - `e.g. Instance ID` - **Are you using `TypeScript`?** - `Y/N` & `VERSION`


mikehardy commented 4 years ago

Hi there! This is confusing to me:

Before using react-native-firebase v6, we were using the firebase package and our API call was finishing within 4-5 sec, but after using react native-firebase v6 (@react-native-firebase/functions), it is taking 15 to 20 sec to fetch data and loading at UI with the same response.

"we were using the firebase package", what exact package and version were you upgrading from? "@react-native-firebase/functions", how exactly are you using functions? That executes in the cloud, so I'm not sure how that would affect performance in this module except via the data returned.

What would help is:

My hunch is there may be a lot of data returned, and there may be some slow parsing or slow transfer from native to javascript across the react-native bridge.

pmakwanaPresentation commented 4 years ago

Hello,

Sorry for missing things.

Let me explain you here.

One month ago, I was using firebase package(https://www.npmjs.com/package/firebase) in my react native app. In my application, we are dealing with firebase functions to get data from firestore.

Here is code snippet of my code

let getUserDetails = firebase.functions().httpsCallable('getUserDetails'); let params = { userId: '124' }

let userData = getUserDetails(params).then((response) => { return response; });

And I am using this response to render UI.

Overall time It was taking is 4-5 seconds.

Now, I wanted to integrate login with apple so I moved to react-native-firebase liberary(https://github.com/invertase/react-native-firebase).

Now, The above code is taking 15-20 seconds.

mikehardy commented 4 years ago

What would help is:

* an example App.js that demonstrates your usage of this module's APIs that show the problem

* example data that is returned from the function

My hunch is there may be a lot of data returned, and there may be some slow parsing or slow transfer from native to javascript across the react-native bridge.

stale[bot] commented 3 years ago

Hello πŸ‘‹, to help manage issues we automatically close stale issues. This issue has been automatically marked as stale because it has not had activity for quite some time. Has this issue been fixed, or does it still require the community's attention?

This issue will be closed in 15 days if no further activity occurs. Thank you for your contributions.

stale[bot] commented 3 years ago

Closing this issue after a prolonged period of inactivity. If this is still present in the latest release, please feel free to create a new issue with up-to-date information.

mikehardy commented 3 years ago

@thanh90 that's unfortunate. However my comment from nearly a year ago still stands and you did not address it? So there is no path forward here as of yet.

What would help is:

* an example App.js that demonstrates your usage of this module's APIs that show the problem

* example data that is returned from the function

My hunch is there may be a lot of data returned, and there may be some slow parsing or slow transfer from native to javascript across the react-native bridge.

roger-ngx commented 3 years ago

@thanh90 that's unfortunate. However my comment from nearly a year ago still stands and you did not address it? So there is no path forward here as of yet.

What would help is:

* an example App.js that demonstrates your usage of this module's APIs that show the problem

* example data that is returned from the function

My hunch is there may be a lot of data returned, and there may be some slow parsing or slow transfer from native to javascript across the react-native bridge.

@mikehardy I can confirm that there's no problem with v12.1.0. the slow caused by my processing after loading data from snapshot.