-
Notifications
You must be signed in to change notification settings - Fork 24.9k
perf: Enable link-time-optimization for performance critical libraries #52488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
I think @cortinico had tried to enable this before, globally in the build, by setting Are there places where this is not getting set? Or is this doing something like setting |
# Enable aggressive compiler optimizations and link-time-optimizations | ||
target_compile_options(reactnative PRIVATE -O3 -flto) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in theory this should not be needed, because the Android NDK toolchain already should be setting those flags for us.
Specifically the release versions of React Native are already built with:
LANGUAGE_COMPILE_FLAGS = -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D__BIONIC_NO_PAGE_SIZE_MACRO -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -O3 -DNDEBUG -flto=thin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On top of this, this would set the compilation flag for both Debug and Release, which is something we don't really want
Yeah see my other comment. We already set |
@mrousavy how reproducible are the wins from using If there is a good win there, I could imagine it making sense to enable for anything prebuilt, since end-users won't often hit the build time impact. But we would want to reconcile the different ways this is enabled. |
let me get back to you on this after some more testing. :) |
Eager to hear your findings @mrousavy :) |
Summary:
Enables Link Time Optimization for performance critical libraries to optimize the native code across modules.
This might increase release build-time a tiny bit (not yet measured), but should improve runtime performance or startup performance a bit (60ms in the Discord app, not yet measured in other apps)
Comparisons
Native Libraries Size
-flto
(current main): 19,4 MB forrn-tester
apk (assembleRelease
, arm64-v8a)-flto
(current PR): 19,4 MB forrn-tester
apk (assembleRelease
, arm64-v8a)..so no difference.
Release apk build time
-flto
(current main): 8:40.24-flto
(current PR): 10:19.57...so 1min 20s increase in build time 😢
Release apk performance
-flto
(current main)-flto
(current PR)I'm not sure how accurate the flashlight measurements are, but according to the average of 10 tests in this CI, enabling
-flto
makes the app start ~70ms (or ~10%) faster... 👀Release apk performance
-flto
(current main): ...-flto
(current PR): ...Changelog:
[GENERAL] [ADDED] - Enabled link-time-optimization to improve performance of some parts of the C++ codebase
Test Plan:
-flto
(release builds!)