React-Native(RN) apps suffer huge performance issues as compared to native apps. During initial development days, such challenges are ignored but as soon as the app grows developers find it difficult to improve. Sometimes, extreme calls to dump the RN app happen. We can escape such steps and you can easily improve the RN app performance, just with little effort.
There are multiple ways to improve RN app performance:
Basics of RN performance:
Hermes: A JS engine to optimizes app start time, reduce APK size, and memory footprints. Follow this guide to setup for your app.
Remove Arrow functions: Every render creates new instances of these functions. When passed to children, it will re-render the child components even when nothing has changed in them.
Simple Reducers: Reducers are just to dispatch store changes, not for complex code logic, avoid that as much as possible.
Use native driver: Enable useNativeDriver=true for all the animations that you use in the app.
React.PureComponent: This works for class components. It does a shallow comparison for the previous and new props, re-renders if they are not equal.
React.memo: Only functional components can leverage this functionality, and works similar to React.PureComponent. React.memo comes with an option to use a custom comparison function, to provide more control over it. For the child functional components use React.memo export const ChildrenMemoComponent = React.memo(ChildFunctionComponent) to memoize.
Whenever parent component props change children’s components are also re-rendered causing huge performance issues. This can be avoided either by using shouldComponentUpdate(), React.PureComponent, React.Memo. Memoization breaks if React creates new functions instances when child component is passed with callback functions from parents. New function instances are created with inline function calls, arrow functions, functions calls inside render. For function component use useCallback hook and for class component define functions outside render and pass references to children.
Debugger warnings and errors: You need to get rid of them, just enable debugging, remove (console.disableYellowBox = true) and fix all the warnings, promise rejections, key errors and other errors too.
Android Studio Profiler: Great tool to find memory leaks in the app. In the below image, the bottom section has lots of bin icons(white color icons) that when android running its garbage collector and repeated icons indicate memory leaks. Perform actions in your app, debug them and fix asap.
React-DevTools: React Profiler provides in-depth component-level leak detection, though it supports RN version ≥ 0.57. Profiler API helps in optimizations like memoization, cost of rendering, sluggish code, re-renders. Go through the docs to check how to integrate it with your app.
Keep your libraries, React version updated to the latest stable versions:
React-native upgrade helper: RN community provides awesome documentation for upgrading RN versions. Major updates are between v0.60.0 and v0.63.0, there will be more errors you will need to fix. Do check out what’s new with v0.64 here.
Upgrade libraries & dependencies: A time-consuming process, during RN update also keep React in mind and upgrade accordingly, v17.0.0 has major changes. For every dependency you upgrade follow the below process:
- Package.json: Segment out the major and minor version upgrades using npm website, “^”(^2.1.2 will use releases from 2.1.2 to <3.0.0) and “~”(~2.1.2 will use releases from 2.1.2 to <2.2.0). For minor version just replacing the version name will do the work. For Major version upgrades check out the version release documentation for breaking changes.
- Code changes: After upgrading the version inside package.json make suitable code changes using Github document and release notes.
- Remove junk: This is also the right time to clean your app code. Try to remove unused codes, folders, files, and dependencies from package.json. Also, to reduce your assets, there is a great tool that does lossless compression, ImageOptim.
That’s 90% of your whole performance improvement job. There are other ways like amalgamation of native code and RN code but we will leave that for some other time.
For more information and to develop mobile application using React Native, Hire React Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – email@example.com or Skype us: “hkinfosoft”.
To develop a custom mobile application using React Native, please visit our technology page.
React Native, next to Flutter and PWA, was called a revolution in cross-platform app development and delivering great mobile experience.
Code repository that’s shareable between platforms? Reusable components? That definitely sounds tempting.
React Native has been praised for its “Learn once, write anything.” objective which means you get a native look and feel of your app for both iOS and Android, and you may also include platform-specific modules.
Some time ago one of our React Native apps, Guild, went public. (Update: Guild has been recognized by Red Herring’s 2019 Top 100 European Startups.)
Is React Native the pick for your next app?
Build a product your users will love to use. Get a highly performant, native app for Android, iOS, and even the Web. Work with our developers and designers to squeeze the most out of your app idea and React Native.
Business Perspective on React Native
Unlike other cross-platform frameworks like Ionic, the Facebook team stresses they acknowledge the differences between different platforms and React Native reflects that. Therefore, you can still include modules specific for iOS and Android like status bars, navigation, or access to native elements like camera and contacts are built according to the platform.
Using libraries such as React Native for Web or ReactXP allows a developer to build a cross-platform app that runs on the Web too, so there’s no need to build separate apps at all. We used ReactXP in one of our projects and it really felt like we’re getting the Web version for free. That’s pretty amazing.
Note that using React Native DOES NOT mean you will not need any help from a native developer. If your app includes many different native features, some work on their side may be required.
Now, when it comes to a team building…
Your front-end web developer can actually become a mobile developer without a need of learning iOS’s Swift or Java/Kotlin for Android. With some knowledge about native UI elements, React, and some platform-specific patterns, React Native is easy to pick up. That is a game changer in terms of building a team as your app will require just one instead of two (or even three if you’re also to conquer the Web).
You can hire JS developers who will be able to deliver for all platforms. Therefore, it is much easier for them to exchange knowledge, conduct a code review, and understand the code. What a difference it makes in terms of time and cost! Not to mention that React Native is all about bringing agility of web development to cross-platform development, with native results.
About the performance…
Some may argue that nothing will surpass the performance of native apps. It may be even true, but products written with React Native are almost identical in how they perform. Sometimes even better. In his great article comparing Native iOS and RN, John Calderaio says:
"(According to) the data we collected through measuring both of the application's CPU, GPU, and Memory during the tasks in each of the four tabs, the apps are also almost identical in how they perform. (…) React Native, winning two out of three categories, comes in first place as the better performing platform."
Wrapping-up: Pros and Cons for Business
- Time and cost efficiency
- Native look and feel of your apps
- Sharing the codebase for iOS, Android, and the Web (with ReactXP and React Native for Web)
- One team for multiple platforms
- Awesome performance
- Need for an expertise from a native developer for some platform-specific modules
- It’s not fully cross-platform, single-codebase approach
If you’re looking for a framework that will let you build a great cross-platform mobile app, check out Flutter.
Bloomberg is a great example of preformant app written with React Native. Image source belitsoft.com.
Developer’s Perspective on React Native
When you start working with React, typically you go with a bundler like Webpack and spend some time considering the right bundling modules for your app. React Native is different, and yet it works similarly to React. It comes with everything you need to just sit down and start writing your code.
Hot/Live reload (similar to Instant Run on Android) is a beloved, killer feature that allows a developer to see introduced changes right away without complete rebuilding of the app. You don’t have to constantly check the results of actions you take which greatly boosts productivity and saves time on compilation.
When it comes to scroll, animations, buttons, text inputs and others, React Native gives an efficient recipe that allows developers to conduct basic tasks easily. Component usage is heavily simplified in comparison to native development and it’s huge.
Adding native modules may not be a piece of cake though.
Whereas there are countless libraries to choose from for iOS and Android, React Native does not exactly shine here. The list of third-party libraries and components is quite long, but in many cases they leave a lot to be desired. When working on modules like device sensors or push notifications, there is a chance you may need some help from a native programmer.
Truth to be told, the Facebook team together with outside collaborators and thriving population of active users constantly work on React Native making it better every day with over 2500 commits from 500 contributors last year.
According to Sophie Alpert, Engineering Manager on React:
Even if it may happen that you’ll need to hack some existing solution or write something from scratch, this will happen more and more rarely.
Wrapping-up: Pros and Cons for a Developer
- You’re web AND mobile developer!
- Great productivity
- Easy setup
- Simplified usage of styling components
- Hot/live reloading feature
- Need of hacking some existing solutions or creating new ones from scratch
- Documentation still needs an upgrade
For more information and to develop web application using React JS, Hire React Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – firstname.lastname@example.org or Skype us: “hkinfosoft”. To develop custom web apps using React JS, please visit our technology page.