Replies: 6 comments 6 replies
-
Great update, thank you!
the "from" value is missing. is it 17 sec? Not that it makes a big difference for the whole post, just for correctness :) |
Beta Was this translation helpful? Give feedback.
-
I remember running the new arch when it first become more easily accessible (0.68 I think) and watching an M1 Max's fans spin up while it chugged along. And almost run out of disk space. Huge W. Really appreciate some of the latest things that the team is doing to fix some of the DX problems of the community!🚀 |
Beta Was this translation helpful? Give feedback.
-
This is insane, awesome work! Maybe also a quick detail; further down the road this will also make it possible to depend on third-party prefabs - as an example, VisionCamera currently depends on Reanimated and has to extract and recompile a bunch of stuff. Lots of exciting stuff! :) |
Beta Was this translation helpful? Give feedback.
-
I am thrilled with the new 0.71 template and prebuilt binaries, particularly for Android. The removal of unnecessary code in the gradle script is a major improvement. |
Beta Was this translation helpful? Give feedback.
-
Thanks for this extremely detailed writeup @cortinico ! We will start thinking about the best mechanism for providing prebuilt libraries in React Native forks (like the TV fork) so that they can enjoy the same developer experience. |
Beta Was this translation helpful? Give feedback.
-
We have encountered an issue when attempting to upgrade examples in the |
Beta Was this translation helpful? Give feedback.
-
tl;dr: From React Native 0.71, you will consume prebuilt artifacts on Android (and iOS to some degree) coming from Maven Central. This brings huge improvements in terms of build time for the New Architecture (and not only, keep on reading!)
Hey all,
As the release of 0.71 is (really) coming closer, we'd like to share another post on some of the improvements for the New Architecture that we'll be shipped in 0.71, similary to this other two posts.
TL;DR of what this means practically for you
react-native
size is reduced by 72%.node_modules/react-native
folder after the first New Architecture build is reduced by 99%.What has changed
Starting from React Native 0.71, we're publishing pre-built artifacts to Maven Central that will be consumed once you build your app.
We're specifically distributing:
This is the implementation of RFC #508 - out-of-NPM package solution for React Native Artifacts. Please refer to the RFC discussion if you're curious on alternative solutions we evaluated.
Published artifacts can be viewed via this barebone HTTP UI here or via the Maven Central Search Engine
Why was this needed
Previously we were publishing everything inside a single monolithic NPM package (
react-native
). This simply doesn't scale as we hit the limit of the NPM package size. The New Architecture relying on C++ and the need to ship debug symbols made our artifacts grew quite significantly.On top of this, using New Architecture on Android meant building from source the whole React Native framework + Hermes engine as we could not distribute prebuilts for them (due to the aformentioned limits).
We had reports of users turning on the New Architecture flag, waiting 1 hour and essentially turning New Architecture immediately back to off as their device was not powerful enough (like here and here). We believe that Developer Experience is crucial for React Native, and bringing build time from seconds to minutes/hours was a major blocker.
Moreover, users reported how the New Architecture was essentially consuming all their public CI credits making a build from source unfeasible for most users.
Why is this important
Practically this change has the following impact:
react-native
is reduced in compressed size from 74.8Mb to 20.5Mb (that's a 72% reduction).10m12s
to32sec
).0.71.0
once, regardless of how many different project you'll have on the same machine. This, together with the removal of the build from source results in reduction of diskspace footprint of thenode_modules/react-native
folder of 99% (from ~10Gb to 69Mb). This results in a overall reduction of the project folder size from from ~12.8Gb to 1.8Gb.-debug
version and not downloading the-release
one unless you're doing a release build.libicu
and other complicated build tools (see below)react-native-mmkv
mentioned that this reduced theirbuild.gradle
logic from 371 to 131 LOC. Smaller build logic => less things that can go wrong between updates.Other wins & opportunities
The list of opportunities and wins is quite long, let me walk through them one by one:
Prefab Support
In 0.71, we ship prebuilts that are Prefab capable. Prefab is a Industry Standard used to exchange
.so
and header files between projects. This allowed libraries likereanimated
orreact-native-mmkv
to easily integrate with React Native.Some reports from folks integrating their libraries with React Native via Prefab:
Historically, libraries that wanted to provide custom C++ code had to re-download Folly, Glog, Boost, Double Conversion, Fmt and Libevent. Each 3rd party library would have to unzip those and include it in their build.
In 0.70, this was happening for both React Native and for every library that was using those sources.
So you would end up with:
node_modules/<react-native-library>
, one for each library. Unzipping all those sources ended up consuming ~900Mb for each library.This ended up devouring a lot of space and bandwidth.
Windows Support
Historically we asked Windows user on New Architecture to do the following:
Build Tools for Visual Studio 2022
orVisual Studio 22 Community Edition
- with the C++ desktop development.libicu
This is sadly a bumpy and lenghty experience, as the Old Architecture did not require those extra steps. 0.71 lifts those requirements bringing New Architecture aligned to the old experience.
Nightlies iOS Support
This change effectively fixed nightlies for iOS.
Every night, we publish a set of Artifact to Sonatype Snapshot repository (a repository similar to Maven Central but reserved for more frequent releases such as nightlies/commitlies).
For iOS specifically, nightlies were broken before we implemented this change as the Hermes Enginer iOS artifact was uploaded to Github Releases. As we created a Github Release only for point/rc/minor releases, nightlies were just failing to download Hermes and were not working.
Similarly, nightilies for Android will consume artifacts from the snapshot repository.
Using nightlies is crucial for us to have a faster feedback loop on our changes. You can read more on how Expo leveraged this change in this blogpost by @Kudo: Testing React Native from the nightly builds
Debug Symbols
The Android artifacts (both React Native and Hermes) contain debug symbols that can be used to symbolicate native stacktraces with the
ndk-stack
command.As more and more users are adopting the New Architecture, native crashes are more frequent and it's crucial that we provide valuable stacktraces for them.
Hash/Signature Validation of artifacts
All the artifacts are hashed (MD5, SHA1, SHA256 and SHA512) and GPG signed. This allows users that are concerned about security (i.e. crypto wallet authors) to verify that our artifacts haven't been tampered. Gradle for instance offer the Gradle Verification feature to automate this flow.
Gradle Configuration Cache
This change allow use to make our build compatible with Gradle Configuration caching. While this is still an 'incubating' feature of Gralde, we can expect it to be enabled by default in Gradle 8.x (or any future version).
Configuration caching allows to reduce even further the build time. On my machine this allow me to reduce an incremental build time from 17 seconds to less than a second using a combination of Configuration Cache,
ccache
and the--active-arch-only
.Maven File layout
Having our artifacts stored in a Maven file layout allows user to potentially proxy/re-host our artifacts inside their corp infra. Solutions like Nexus OSS allows companies to mirror Maven Central and speed-up internal builds while protecting them from external downtimes.
Benchmarks Methodology
For future reference, I'm sharing my benchmarks setup. All the metrics have been collected on a Apple MacBook Pro M1 Max - 64Gb, which is a high-end machines. Users on lower-end devices like MacBook Air will see way more benefits from this change.
Disk space metrics have been collected using finder using the "size on disk" metric.
Build time metrics have been collected with the following commands:
To recreate a scenario that simulates the "first user experience" we're not using niether the
--active-arch-only
norccache
described in the Speeding up your Build phase guide.Similarly, the download time (
yarn
or Gradle download time) has been excluded. All the tests for 0.71 are executed under the assumption that a version ofreact-android
is already downloaded previously on the machine. This is done to exclude variability of different network connections.Here the results.
node_modules/react-native
(New Arch)We're happy to collect feedback on this specific change here and answer questions/follow-up if there are any.
Beta Was this translation helpful? Give feedback.
All reactions