-
Notifications
You must be signed in to change notification settings - Fork 23
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
fix: shorebird engine builds are larger than expected, fix and document size #19
Comments
I did it on default Flutter's counter project with and without Shorebird. Without the Shorebird, the size was 17.9, and with the shorebird size was 24.5. Diff is ~7MB which is more than what is mentioned in the document (1MB). // @eseidel |
Will investigate, thanks. |
Yeah, something is very wrong. I wrote a tool to compare:
|
I added support for Android, it's also bigger than expected. These iOS sizes are uncompressed (which isn't what will ship) and the Android sizes are semi-compressed. The jar itself is compressed, but will be re-compressed as part of the apk.
|
Comparing https://github.com/shorebirdtech/build_engine/blob/main/build_engine/mac_build.sh and https://github.com/flutter/engine/blob/main/ci/builders/mac_ios_engine.json I don't see any obvious compile-flag differences. |
This could explain it: shorebirdtech/buildroot@d6c410f If there are a ton of symbols that slip through on iOS as a result? |
https://github.com/evmar/bloat is a tool we used to use for this on Chromium. |
I suspect this could be part of our problem: I'm not actually sure how that interacts with .a files (if it does at all), since I would expect the stripping to happen at a later stage? |
I've compared the Still trying to figure out what the right way to expose only the symbols we need from our Rust code into the Flutter Engine w/o causing (at least iOS) to also then re-expose all of those symbols in Flutter.framework. |
OK, learned a bit about stripping our rust output tonight. This should work:
-x makes it hide/mangle all non-global names so they dead strip correctly. With this exports list:
(Need to add the rest of those to make this real.) We may need to turn the .o back into a .a to link it into libflutter, using |
|
Generated symbols.exports with:
|
I added this into our rust build script, only to then realize that rust build scripts run before cargo build, not after, so this can't work: // We only do our re-link for iOS targets right now.
let target = env::var("TARGET").unwrap();
if target != "aarch64-apple-ios" {
return;
}
// ld -r -o foo.o -exported_symbols_list library/symbols.exports target/aarch64-apple-ios/release/libupdater.a -arch arm64 -x
let out_dir = env::var("OUT_DIR").unwrap();
// list files in outdir
let crate_root = env::var("CARGO_MANIFEST_DIR").unwrap();
let symbols_path = Path::new(&crate_root).join("symbols.exports");
let status = Command::new("ld")
.args(&[
// -r Merges object files to produce another mach-o object file with file type MH_OBJECT.
"-r",
// -x Do not put non-global symbols in the output file's symbol table.
// Hides non-global symbols from the output file's symbol table and
// makes dead code stripping work.
"-x",
// arch is required when working with mach-o due to fat binaries.
"-arch",
"arm64",
"-exported_symbols_list",
symbols_path.to_str().unwrap(),
"-o",
"libupdater.o",
"libupdater.a",
])
.current_dir(&Path::new(&out_dir))
.status()
.unwrap();
panic!("status: {}", status); Will work on a change to our gn/ninja files instead. |
https://darkcoding.net/software/a-very-small-rust-binary-indeed/ may also be helpful. |
Thought about this more. The steps to fix this:
|
When we get to this shorebirdtech/engine#49 was one start, but we should measure first. |
Description
Comparing the output of
flutter build apk --release
vs.shorebird build apk --release
should give you a rough idea.The text was updated successfully, but these errors were encountered: