React native becomes slow in mobile. Javascript code takes 3-4 seconds to execute in emulator however, when installed in apk it beocmes slow - react-native

React-native application becomes very slow and takes around 2 mins to run when installed in mobile. However, in emulator it takes around 3-4 secs. The code has a lot of javascript code and for loops written in javascript.

This might be due to your emulator hardware is less compared with physical device and you can usually experience that difference of loading time, to overcome that loading we have a concept of Splash Screen which will hide that loading from users.

Related

React Native Performance issue with array sorting

I'm in the process of checking if React-Native is capable of handling a point in my native application that based on it I will take the decision whither or not to migrate my app to React Native.
Here is the scenario that I'm testing. The app is connecting to a server using socket.io. Then I'm requesting the full product list (350 product). Once I receive the list I sort it ascending according to their price using native code (Objective C for iOS and Java for Android). Then I show the result.
Then The app just keep listing to the server updates. The server send me update about 60 products every 10ms. Every time I should be able to sort them and and render them.
Now this was terrible performance wise. CPU is always between 160% and 200%. Rendering is extremely slow.
First approach I took was to look for a React-Native module that make the same concept as recycle view in Android and collection view in iOS. I was able to find one (recyclerlistview) (https://github.com/Flipkart/recyclerlistview). Unfortunately it didn't effect much on the rendering. Then I decide to limit the view to 17 product only. Which made significant improvement on the rendering (steady 60FPS).
But that made the rendering extremely fast for the human eye to keep track of the changes. So I made a small change, I used the forceUpdate function inside an interval that runs every 1 second which made it readable.
But I'm still unable to find a solution to my CPU huge usage. I even changed it from normal built it sorting to use a merge sort algorithm. But still I'm unable to lower the usage at all.
Any work around this kind of performance issue.
Extra info
setState is only run once at the start of the app. So there is no rendering being made except through the forceUpdate function.
React: 16.3.1
React-Native: 0.55.2
Sort the array using merge sort algorithm in native code (objective c in iOS, Java in Android) then render the screen through the forceUpdate function using an interval (ex: 1second). This way the CPU won't exceed the 80% mark and the energy impact will be medium. Since this is the only intensive screen in the mobile application then there is no need to do anything else.
P.S
remember once you get out of this screen or navigate to another screen to send to the server request to stop sending updates.

React Native Android Slow Performance without Chrome Debug

I am having performance issues on React Native Android. I am using Redux.
The issue is that my app works fine (fast) when chrome debug is on. The moment i turn off the remote debugger, the performance becomes very sluggish. I was just wondering if this is normal. I have read other thread saying that in debug mode, the performance is executed on chrome itself so it's faster. Is such a big gap in performance normal?
Thanks.
I have head the same performance issues and that was quite bad experience. You need to remove any console.log('show_me_some_data') and then you will get better performance. I think react-native is trying to find remote debugger every time then he meets console.log. React need time for this and that's why performance is reduced. This is just my suggestion, but that worked for me.
Hope this will help someone.

Our Trigger.IO app is 9MB, is this too large & how can we reduce app loading time?

Our app is currently extremely slow when first booting up.
What are the key elements that contribute to app loading time and how can we accelerate that process?
We load very simple note objects into memory upon launch and intend to use plugins for native databases soon.
We plan on minifying as well as using native plugins for storage, what other strategies can we employ?
This guest post by hojoki has been pretty helpful as well.
Duplicate resources
In trigger.io all resources (Android + iOS) are packaged together. E.g. the splash screen Android is included both in the iOS and Android build -- and vice versa. Perhaps that's one reason for the size?
And if so, building two separate apps, one per platform, may be one way to work around that issue. Obviously the ability to exclude non-platform resources would be even better, but that doesn't work right now.
File size
Run minification on all js/css, reduce png/jpeg file-sizes.

App crashes on launch with < 256 RAM iOS Devices

The Info
I recently launched an app on the AppStore. After testing on the simulator thousands of times, and actual devices hundreds of times we finally released our app.
The Problem
Reviews started popping up about app crashes when the user launches the app. We figured that the app crashes on launch on iOS devices with less than (or equal to) 256 Mb of RAM. The following devices are devices our app supports with less than 256:
iPod Touch 4G
iPhone 3GS
iPad 1
The app doesn't always crash. Sometimes it launches fine and runs smoothly. Other times it crashes. The time from launch (when the user taps the icon) to crash is usually two seconds, which would mean that the system isn't shutting it down.
Findings
When using Instruments to test on certain devices, I find the following:
There are no memory leaks (I'm using ARC), but there are memory warnings
Items are being allocated like crazy. There are so many allocated items, and even though I'm using ARC it's as if ARC isn't doing what it's supposed to be doing
Because of what I see as "over-allocation", the result is:
This app takes (on average) 60 MB of Real Memory and 166 MB of Virtual. When the app launches the memory being used quickly increases until it reaches about 60 MB at which point the view has been loaded.
Here is a snapshot of the Activity Monitor in Instruments:
I know that those figures are WAYY to high (although the CPU % never really gets up there). I am worried that ARC is not working properly, or the more likely case: I'm not allocating objects correctly. What could possibly be happening?
The Code and Warnings
In Xcode, there are only a few warnings, none of which pertain to the app launch or any files associated with the launching of the app. I placed breakpoints in both the App Delegate and my viewDidLoad method to check and see if the crash occurred there - it didn't.
More Background Info
Also, Xcode never generates any errors or messages in the debugger. There are also no crash reports in iTunes Connect, it just says, "Too few reports have been submitted for a report to be shown." I've added crash reporting to my app, but I haven't released that version.
A Few Questions
I started using Obj-C just as ARC arrived, so I'm new to dealing with memory, allocation, etc. (that is probably obvious) but I'd like to know a few things:
How can I use #autoreleasepool to reduce my memory impact? What do I do with memory warnings, what do I write in the didRecieveMemoryWarning since I'm using ARC?
Would removing NSLog statements help speed things up?
And the most important question:
Why does my app take up so much memory and how can I reduce my whopping 60 MB footprint?
I'd really appreciate any help! Thanks in advance!
EDIT: After testing on the iPhone 4 (A4), we noticed that the app doesn't crash when run whereas on devices with less than 256 MB of RAM it does.
I finally solved the issue. I spent a few hours pondering why my application could possibly take up more RAM than Angry Birds or Doodle Jump. That just didn't make sense, because my app does no CALayer Drawing, or complex Open GL Graphics Rendering, or heavy web connection.
I found this slideshow while searching for answers and slide 17 listed the ways to reduce memory footprint. One thing that stuck out was PNGCrush (Graphics Compression).
My app contains a lot of custom graphics (PNG files), but I hadn't thought of them affecting my app in any way, apparently images (when not optimized properly) severely increase an applications memory footprint.
After installing PNGCrush and using it on a particularly large image (3.2 MB) and then deleting a few unused images I ended up reducing my apps memory footprint from 60+ MB and severe lag to 35 MB and no lag. That took a whopping five minutes.
I haven't finished "crushing" all my images, but when I do I'll update everyone on the final memory footprint.
For all those interested, here is a link to a blog that explains how to install PNGCrush (it's rather complicated).
UPDATE: Instead of using the PNGCrush process (which is very helpful, although time consuming with lots of images) I now use a program called ImageOptim that provides a GUI for multiple scripts like PNGCrush. Heres a short description:
ImageOptim seamlessly integrates various optimisation tools: PNGOUT, AdvPNG, PNGCrush, extended OptiPNG, JpegOptim, jpegrescan, jpegtran, and Gifsicle.
Here's a link to the website with a free download for OS X 10.6 - 10.8. Note, I am not a developer, publisher or advertiser of this software.

scrollview scrolls smooth in simulator but not in device?

i have page control sample from apple and using it in my application... in my application scrolling is running smooth in simulator but when installed on device it is not smooth.
does someone knows about it? i am also doing some flip animation.it's also not running smoothly
The fact that it is running slower on the device (potentially several times slower) is completely normal. The simulator is not cycle accurate, it has access to all of the RAM, GPU resources, and processors on the host system.
Without actually knowing what you are doing no one can tell you how to improve performance, but there is nothing wrong with your app that is making it run slower and choppier on the device than in the sim that can be fixed to make it perform like it does in the simulator.