Live data from Hacker News

Tempted to Abandon React Native for Native Android

kelvinpompey.me

11–20 of 63 posts

Re: Tempted to Abandon React Native for Native Android

#11
To summarize this article: The author really enjoyed using React Native up until he hit some performance issues related to loading large images on certain versions of Android.

He doesn't go into what specifically the performance issues were, any techniques he used to profile his app, what third party libraries he tired or anything.

Performance issues happen all the time with native apps that don't use React Native. Optimizing is a core part of what a software engineer does. Giving up on weeks of learning without a good reason seems like a poor choice to me.

As it so happen's I have been working with a colleague of mine who just fixed a React Native performance issue relating to images on Android on older devices. The author might want to check out the following article:

https://facebook.github.io/react-native/docs/performance.htm...

Our particular issue was solved by the following:

"This is especially true when you have text with a transparent background positioned on top of an image, or any other situation where alpha compositing would be required to re-draw the view on each frame. You will find that enabling shouldRasterizeIOS or renderToHardwareTextureAndroid can help with this significantly."

Apart from the above, this article is pretty shallow, which is sad because I would love to read a good article on React Native's performance. Perhaps I will write one if people are interested.

Re: Tempted to Abandon React Native for Native Android

#12
post #2

Sounds like a good opportunity to build some performance-tuning muscle :) Whether using RN or java, you'll want to know how to debug memory/performance issues on Android - they're mostly unavoidable on mobile devices! (And maybe you can file some issues against React Native, too, which would be great and help the platform)

That's a fair point about the opportunity to build some performance-tuning muscle but I imagine to do that would require solid knowledge of both React and Android. Where do I start? I am more inclined to go towards the native Android side first. Aa a follow up, I just did a test with a native Android app doing the same thing: getting an image through an Intent. With the native Android app, the same image that was cra…

Have you read this:

https://facebook.github.io/react-native/docs/performance.htm...

It might help with some of the performance issues you encountered.

Even if you decide to abandon React Native and just do Native Android or iOS, you are going to have to deal with performance issues at some point in your career.

Re: Tempted to Abandon React Native for Native Android

#13
I've been playing a lot with React Native over the last year; professionally for almost 4 months now. This really aligns with my experience. I don't share the same opinion of going back to native code though.

This really is a fantastic platform. You really can, today, write native cross platform and web apps with the same code base. With few exceptions, everything from including native modules to upgrading is painless. The UI metaphor is fantastic, the tooling is superb, the editor support is there, the community is growing. It's a great place to be.

It's not without it's warts though. From my experience, the real problems stem from the 3rd party native modules. It's not even their fault, the platform is just moving so fast. As recently as the 0.40 release, every native module out there was broken on iOS for a short period of time. I was the first to submit PR's to two fairly widely used ones, and that was multiple days after the release. On this point, I believe this is more indicative of a community that generally doesn't upgrade their projects right away- a combination of painful prior experience and a deep seeded distaste of having to re-release their app on all stores as you can leverage a tool like Microsoft Code Push to change the bundle as long as it is compatible with the native shell.

Of the two RN projects I'm working, both have at least one dependency pinned to a Github fork I have of a project, waiting for my patches to be released. This sounds worse than it is, as the majority of native modules are hilariously small and easy to modify, but it still is worth mentioning as a point of friction today. As the community grows, I expect this will diminish.

Re: Tempted to Abandon React Native for Native Android

#14
post #8

My next foray into mobile is going to be with this- https://www.nativescript.org/ Digging through the api it just looks much more capable in directly calling android instead of abstracted cross platform blobs.

For the types of problems the author is describing, NativeScript would not be there to support you. NativeScript surfaces the device API's across the JS bridge, and the serialization across this bridge and pressure on it will always lead to less performant code. You would have to drop to native modules all the same, and then what have you solved?

https://docs.nativescript.org/runtimes/android/advanced-topi...

Perhaps I'm misunderstanding your concern, but it doesn't look like js allocates for the actual object just a proxy for the java.

Re: Tempted to Abandon React Native for Native Android

#15
post #13

I've been playing a lot with React Native over the last year; professionally for almost 4 months now. This really aligns with my experience. I don't share the same opinion of going back to native code though. This really is a fantastic platform. You really can, today, write native cross platform and web apps with the same code base. With few exceptions, everything from including native modules to upgrading is painles…

Yep, exactly my experience. I love React Native but if your not used to the Javascript style of million's dependencies your in for a world of pain.

It's critical to spend more time vetting third party React Native/Javascript libraries as the quality level varies way more than with native libraries.

As a native developer I hadn't spent a lot of time working deeply with npm. One thing to be careful about when saving packages to your project is the use of ^ versus ~. See:

http://stackoverflow.com/questions/22343224/whats-the-differ...

" the tilde matches the most recent minor version (the middle number). ~1.2.3 will match all 1.2.x versions but will miss 1.3.0.

The caret, on the other hand, is more relaxed. It will update you to the most recent major version (the first number). ^1.2.3 will match any 1.x.x release including 1.3.0, but will hold off on 2.0.0."

Considering the volatility of some third party Javascript libraries, this can cause quite a bit of pain.

It's worth doing the following in your home directory add save-prefix=~ to your .npmrc and all npm install's in the future will automatically add ~ instead of ^

Re: Tempted to Abandon React Native for Native Android

#16
If you already know how to do the image related task in Native Android, you could spike a test project and verify that it's performant on the smaller devices and the problem could be attributed to React Native alone. Then it's a matter of porting the high level API to JS.

Given that you believe this is a memory-related problem, perhaps it's because the image is too large to fit into the available memory, and having React Native made it worse.

Re: Tempted to Abandon React Native for Native Android

#17
post #11

To summarize this article: The author really enjoyed using React Native up until he hit some performance issues related to loading large images on certain versions of Android. He doesn't go into what specifically the performance issues were, any techniques he used to profile his app, what third party libraries he tired or anything. Performance issues happen all the time with native apps that don't use React Native. O…

I analysed react-native's performance issues with images and out-of-memory-errors a while back.

Their (and their image library Fresco's) problem is that they make heavy use of object-finalizers, which is an error in Java and especially Android.

I reported a couple of bugs, but got dismissed:

https://github.com/facebook/react-native/issues/8711

https://github.com/facebook/react-native/issues/8780

https://github.com/facebook/fresco/issues/1363

I found this rather frustrating.

I also found out that using plain java-serialization/string over the JS/Java bridge is twice as fast compared to their homegrown memory-management written in C. Again, a bugreport, again, dismissed.

https://github.com/facebook/react-native/issues/10504

It seems that Facebook's Java programmers don't know Java very well.

Re: Tempted to Abandon React Native for Native Android

#18
post #17
post #11

To summarize this article: The author really enjoyed using React Native up until he hit some performance issues related to loading large images on certain versions of Android. He doesn't go into what specifically the performance issues were, any techniques he used to profile his app, what third party libraries he tired or anything. Performance issues happen all the time with native apps that don't use React Native. O…

I analysed react-native's performance issues with images and out-of-memory-errors a while back. Their (and their image library Fresco's) problem is that they make heavy use of object-finalizers, which is an error in Java and especially Android. I reported a couple of bugs, but got dismissed: https://github.com/facebook/react-native/issues/8711 https://github.com/facebook/react-native/issues/8780 https://github.com/fa…

Thanks for all the awesome links! The Android portion of React Native is far behind iOS.

"I also found out that using plain java-serialization/string over the JS/Java bridge is twice as fast compared to their homegrown memory-management written in C"

We ran into some issues relating to this when wrapping some native code on Android. I'll pass your links on to my Android colleague.

Re: Tempted to Abandon React Native for Native Android

#19

Earlier quoted context omitted.

I've seen large images give native iOS and Android apps trouble. It's a challenging problem to solve no matter what. And using ReactNative or NativeScript for the high level UI and a plug-in to handle pushing the bits around is probably still a better choice than going completely native.

That's an interesting idea. The code to select and resize the images are native third-party plugins so in this case I am not sure anything more could be done. I thought maybe the problem was that the app had to switch to another app to select the image. I reimplemented the code using a pure JavaScript plugin based on React Native's CameraRoll API to avoid switching apps and it still crashed when the image was selecte…

Just a wild guess - you said opening for processing. Depending on what you're doing with the file and how you're opening it the whole data get's passed over the bridge resulting in some catastrophic memory allocations. I would recommend tapping into the bridge communication and start checking if everything stays where it should. Some picker modules tend to send base64 encoded file beside the URL.

Re: Tempted to Abandon React Native for Native Android

#20
post #16

If you already know how to do the image related task in Native Android, you could spike a test project and verify that it's performant on the smaller devices and the problem could be attributed to React Native alone. Then it's a matter of porting the high level API to JS. Given that you believe this is a memory-related problem, perhaps it's because the image is too large to fit into the available memory, and having R…

I did just that. I created a native Android project that selected an image from the image picker and displayed it in an image view. I tested it with a few images and it worked. Even the image that crashed the React Native app.

"Given that you believe this is a memory-related problem, perhaps it's because the image is too large to fit into the available memory, and having React Native made it worse. "

This is precisely what I think it is.

Post reply on HN