Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make Android app start faster by disabling JS bundle compression #7751

Merged
merged 2 commits into from
Feb 17, 2025

Conversation

mrousavy
Copy link
Contributor

Disables compression for the .bundle resource files in the .apk.

This makes the .apk a bit bigger, but improves startup time on Android - we measured a 400ms startup improvement (12%) in one of our apps.

Based on facebook/react-native#49449

@mrousavy mrousavy marked this pull request as draft February 15, 2025 15:36
@mrousavy
Copy link
Contributor Author

mrousavy commented Feb 15, 2025

Draft because I couldn't yet figure out how to make this work with Expo Config Plugins.

fixed

@mrousavy mrousavy marked this pull request as ready for review February 15, 2025 18:14
@mrousavy
Copy link
Contributor Author

Okay now it works, I fixed it!

@gaearon do you guys have any TTI measurements in BlueSky? If yes, would be great if you could run those in release builds to see how much faster it got with my PR.

I can't seem to be able to build the app in release.

@mrousavy mrousavy changed the title perf: Disable Android compression to speed up app startup Make Android app start faster by disabling JS bundle compression Feb 15, 2025
@surfdude29
Copy link
Contributor

FYI @gaearon isn't working at Bluesky anymore:

https://bsky.app/profile/danabra.mov/post/3lhcrrc76s22i

@gaearon
Copy link
Collaborator

gaearon commented Feb 15, 2025

There's this:

console.log(`Time to first paint: ${initMs} ms`)

You can get it to show up (and see it in logcat) by commenting out the "remove console" plugin in the prod Babel config.

I can't seem to be able to build the app in release.

Not sure if anything is broken, last time I tried yarn android --variant release was working fine.

@mozzius
Copy link
Member

mozzius commented Feb 17, 2025

Ok results are in:

Current (mean of 10 runs): 805ms

With change (mean of 10 runs): 773ms

Improvement: 4% faster!

That's not nothing, and this was on a Pixel 7A. I'd imagine that lower-powered phones might see more benefit.

Copy link
Member

@mozzius mozzius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

@mozzius mozzius merged commit 326445d into bluesky-social:main Feb 17, 2025
7 checks passed
estrattonbailey added a commit that referenced this pull request Feb 17, 2025
* origin/main:
  Make Android app start faster by disabling JS bundle compression (#7751)
  Nightly source-language update
  Update tests
  Screen for searching user's posts (#7622)
  Add translations missed in last PR (#7748)
  1.98 release: Pull latest from crowdin (#7746)
  [Instrumentation] Signin (#7742)
  Reenable router events (#7735)
  Nightly source-language update
  Bitdrift integration (#7728)
  Use effective filtering for feeds (#7736)
  Update PostInteractionSettingsDialog.tsx (#7726)
@mrousavy
Copy link
Contributor Author

I haven't dug too deeply, but it looks like initMs is calculated from __BUNDLE_START_TIME__:

const initMs = Math.round(
// @ts-ignore Emitted by Metro in the bundle prelude
performance.now() - global.__BUNDLE_START_TIME__,
)

This sounds wrong to measure this specific improvement, since the performance gains already start a bit earlier than that; when Android starts to load the actual .bundle from resources (see _CompressedAsset::getBuffer).

So if you measured 4% with this change, you only measured the mmap difference. The real improvements might be much bigger because we didn't measure the uncompression part of this whole thing. Anyways; it's faster now 😄

@gaearon
Copy link
Collaborator

gaearon commented Feb 18, 2025

Seems like you’d want to measure the time from the first native app log to when this console log comes in.

@mrousavy
Copy link
Contributor Author

yep

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants