Skip to content
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 bloated liblimbo_sqlite3.a binary size #714

Open
penberg opened this issue Jan 16, 2025 · 2 comments
Open

Fix bloated liblimbo_sqlite3.a binary size #714

penberg opened this issue Jan 16, 2025 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@penberg
Copy link
Collaborator

penberg commented Jan 16, 2025

There's no reason for liblimbo_sqlite3.a to be this big:

limbo % ls -lh target/release/liblimbo_sqlite3.a
-rw-r--r--  1 penberg  staff    37M Jan 16 15:12 target/release/liblimbo_sqlite3.a

What's odd is that the shell image size makes much more sense and it packs the same functionality...

limbo % ls -lh target/release/limbo
-rwxr-xr-x  1 penberg  staff   3.8M Jan 16 15:13 target/release/limbo

Furthermore, the dynamic library is also fine:

sqlite3 % ls -lh ../target/release/liblimbo_sqlite3.dylib
-rwxr-xr-x  1 penberg  staff   3.1M Jan 16 15:16 ../target/release/liblimbo_sqlite3.dylib
@penberg penberg added enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed labels Jan 16, 2025
penberg added a commit that referenced this issue Jan 16, 2025
This reduces `liblimbo_sqlite3.a` size from 37M to 20M.

Refs #714
penberg added a commit that referenced this issue Jan 16, 2025
..to reduce `liblimbo_sqlite3.a` size from 37M to 20M. As it turns out,
LLVM emits its bitcode into static libraries when LTO is enabled to be
"more aggressive" in optimizations

Refs #714
penberg added a commit that referenced this issue Jan 16, 2025
..to reduce `liblimbo_sqlite3.a` size from 37M to 20M. As it turns out,
LLVM emits its bitcode into static libraries when LTO is enabled to be
"more aggressive" in optimizations

Refs #714
penberg added a commit that referenced this issue Jan 17, 2025
..to reduce `liblimbo_sqlite3.a` size from 37M to 20M. As it turns out,
LLVM emits its bitcode into static libraries when LTO is enabled to be
"more aggressive" in optimizations

Refs #714
penberg added a commit that referenced this issue Jan 17, 2025
This reduces `liblimbo_sqlite3.a` size from 37M to 15M.
Refs #714

Closes #715
@krishvishal
Copy link
Contributor

@penberg what linker are you using?

I'm using the default gcc linker and I'm getting larger sizes on the main

ls -lh target/release/liblimbo_sqlite3.a
-rw-r--r-- 2 kv kv 49M Jan 21 13:15 target/release/liblimbo_sqlite3.a

Previously I was using mold linker and it produced even larger (~65 MB) binary.

@LtdJorge
Copy link
Contributor

LtdJorge commented Feb 7, 2025

There's no reason for liblimbo_sqlite3.a to be this big:

There kind of is, since the archive has to bundle all of the dependencies, at least:

List of object files in the archive
  • limbo_sqlite3.limbo_sqlite3.3d70c50c1d264586-cgu.0.rcgu.o
  • limbo_sqlite3.44hf5c7dhfj3tffno2shtvjlx.rcgu.o
  • env_logger-cd2a9683c61eb39e.env_logger.c7ffc236fc9a6a39-cgu.0.rcgu.o
  • env_filter-78d427e6f048df1a.env_filter.5e0610c31c2d40c0-cgu.0.rcgu.o
  • limbo_core-c6b37a2df739f5f4.limbo_core.b1460fcd8cd4fbd9-cgu.0.rcgu.o
  • mimalloc-ac7b23dee00a3db2.mimalloc.8b79865bb2c61746-cgu.0.rcgu.o
  • libmimalloc_sys-cd4ef2680c636f41.libmimalloc_sys.a3a3424221597170-cgu.0.rcgu.o
  • 5a07bf3761bb5df8-static.o
  • hex-53a14409b81fd75c.hex.92f8f039ee001944-cgu.0.rcgu.o
  • julian_day_converter-62cde7286e7bff24.julian_day_converter.59e2edf4baaaa423-cgu.0.rcgu.o
  • limbo_time.limbo_time.53bdf122ad4bcc99-cgu.0.rcgu.o
  • limbo_uuid.limbo_uuid.debdd0bef7fdbe2e-cgu.0.rcgu.o
  • uuid-020127c55ed878af.uuid.21c7a14da18fdf2f-cgu.0.rcgu.o
  • io_uring-d3ddc53d8329c42a.io_uring.135869b51bbc7886-cgu.0.rcgu.o
  • bitflags-ae27daf5d0e4934d.bitflags.f4829fce2eb64f99-cgu.0.rcgu.o
  • polling-38c79eeefb92dafd.polling.8bc87093f02ed8f4-cgu.0.rcgu.o
  • rustix-3c8334ae9c95db8e.rustix.581ca281767b1c88-cgu.0.rcgu.o
  • linux_raw_sys-71ad4a220999a2e5.linux_raw_sys.9ce0565d4d22dc75-cgu.0.rcgu.o
  • tracing-db065ca29ec73803.tracing.197c8682328b1715-cgu.0.rcgu.o
  • pin_project_lite-de3c2a5e3017f969.pin_project_lite.f69a502b75c1bd86-cgu.0.rcgu.o
  • tracing_core-07aca6f857596005.tracing_core.29113a6dd333be98-cgu.0.rcgu.o
  • once_cell-599af5bda608e556.once_cell.88d1b59eda254227-cgu.0.rcgu.o
  • libloading-91df74686429e287.libloading.88c7eaf69761da09-cgu.0.rcgu.o
  • regex-87ce232f2c8b7b92.regex.22f9188d54a0a9e5-cgu.0.rcgu.o
  • regex_automata-8d7a5c6af9cf3b36.regex_automata.f170421cc6d1438a-cgu.0.rcgu.o
  • aho_corasick-016fcbc1fd5f5f8d.aho_corasick.d9522feb3f529824-cgu.0.rcgu.o
  • regex_syntax-c8d7fc901da1dfe3.regex_syntax.485a15d4c4215ad6-cgu.0.rcgu.o
  • parking_lot-97d1cb8d72a54bb6.parking_lot.38dfcc09a44d2fba-cgu.0.rcgu.o
  • parking_lot_core-33759cb6ceda7b1b.parking_lot_core.788b06b33b6ae67d-cgu.0.rcgu.o
  • smallvec-b49122bd7b1c2cd5.smallvec.fcebbc791b334945-cgu.0.rcgu.o
  • lock_api-3f0ea0ccab1e1391.lock_api.168da3671f0255cd-cgu.0.rcgu.o
  • scopeguard-91a2376d52fd3457.scopeguard.e85d7125f37953a7-cgu.0.rcgu.o
  • crossbeam_skiplist-4c5c361229e5fdc1.crossbeam_skiplist.edbe177a13f14507-cgu.0.rcgu.o
  • crossbeam_epoch-2c683a33aa247d28.crossbeam_epoch.3c93e93242561c98-cgu.0.rcgu.o
  • crossbeam_utils-9340898dc74dddea.crossbeam_utils.92fd9cfe1ff56578-cgu.0.rcgu.o
  • jsonb-d196d1df94847215.jsonb.e9985d84802543a2-cgu.0.rcgu.o
  • fast_float2-adb5aff286628438.fast_float2.32a78678008b5a04-cgu.0.rcgu.o
  • nom-dc5b68012844f12d.nom.c018a010b42deebe-cgu.0.rcgu.o
  • rand-d9141586f8e67baa.rand.767fbff576ee656a-cgu.0.rcgu.o
  • rand_chacha-ab48fbb40d5144e2.rand_chacha.4ea283e458aeb9cd-cgu.0.rcgu.o
  • ppv_lite86-07582eac94f32a79.ppv_lite86.6c16d1bb642d1fe6-cgu.0.rcgu.o
  • zerocopy-bb2b654f2c20a650.zerocopy.6ee3e7d72ede4a25-cgu.0.rcgu.o
  • rand_core-14ccf75a8343ebf5.rand_core.20293467e299cbae-cgu.0.rcgu.o
  • getrandom-0730b72cf36c6c5f.getrandom.731356465afc13eb-cgu.0.rcgu.o
  • libc-50fd65bfd022965e.libc.586139b313991818-cgu.0.rcgu.o
  • cfg_if-bf28d3c1989941bf.cfg_if.561b0f9ae6671c31-cgu.0.rcgu.o
  • serde_json-88227e5bf574994e.serde_json.10506d904c8a17a3-cgu.0.rcgu.o
  • itoa-4a4cecac0394587d.itoa.fba1cde851ce1d01-cgu.0.rcgu.o
  • ryu-cece4d11299db20a.ryu.6275f148060e3d67-cgu.0.rcgu.o
  • ordered_float-6d05e5a429e252a2.ordered_float.5262725e54360372-cgu.0.rcgu.o
  • byteorder-5f3724cd1ad2f441.byteorder.c9670806f4ca6168-cgu.0.rcgu.o
  • pest-970fdc5e831a7569.pest.9d7fbb741e2b038-cgu.0.rcgu.o
  • ucd_trie-01d691dd29139615.ucd_trie.e1b57c69570dca82-cgu.0.rcgu.o
  • thiserror-3c69338fcf8f7385.thiserror.84f86e17e296750b-cgu.0.rcgu.o
  • cfg_block-80f62701c47a4c5f.cfg_block.821b3c5d68b4e048-cgu.0.rcgu.o
  • chrono-d6776fd658457cc3.chrono.1afa0679a15b4f8-cgu.0.rcgu.o
  • num_traits-49f63db03419b60f.num_traits.1e4287152e47149b-cgu.0.rcgu.o
  • iana_time_zone-7599b600de7b0ab3.iana_time_zone.a877e3d9750d9048-cgu.0.rcgu.o
  • sqlite3_parser-b3b012b12ddae62c.sqlite3_parser.adca800cd6b38694-cgu.0.rcgu.o
  • phf-7c11f07174d803f4.phf.790a9f0e37a7df41-cgu.0.rcgu.o
  • phf_shared-1675a0a50c2956ae.phf_shared.e17c1b19d1d9d8c2-cgu.0.rcgu.o
  • siphasher-4f275ce7da5e295b.siphasher.65a0c3180895c9b1-cgu.0.rcgu.o
  • strum-7856785ead5df2e9.strum.b6d5f2c63ec9542c-cgu.0.rcgu.o
  • bitflags-f7c7493091509a35.bitflags.88d73d1a22abdabc-cgu.0.rcgu.o
  • miette-f7736899133cbeb2.miette.43812cca5d3acc78-cgu.0.rcgu.o
  • unicode_width-c494c9f4f0a84265.unicode_width.7ed768c36e6145fa-cgu.0.rcgu.o
  • indexmap-41d0534bb2b63524.indexmap.36a1bcbd1be79baa-cgu.0.rcgu.o
  • equivalent-7d9da6785b361743.equivalent.5b270c6286fcca4e-cgu.0.rcgu.o
  • hashbrown-3372a7819a1dfd09.hashbrown.89069fb66b464f86-cgu.0.rcgu.o
  • serde-d99e46c810f6c8b6.serde.8daa394eb4756d4-cgu.0.rcgu.o
  • memchr-65ecdcfcb7f50a11.memchr.d91e12cf205dd161-cgu.0.rcgu.o
  • uncased-65127d5f55bd73a1.uncased.46a52ef7e1f5a68c-cgu.0.rcgu.o
  • limbo_ext-ad88e5cc128b0ea5.limbo_ext.5589e4f1faab46eb-cgu.0.rcgu.o
  • fallible_iterator-26ca5a0c82f8c16d.fallible_iterator.2be0ac6e7744ab71-cgu.0.rcgu.o
  • thiserror-a284fd2d0e1ac243.thiserror.b5dc37ed2b4a7fd4-cgu.0.rcgu.o
  • log-ac32031385f7f656.log.60718ae287befbe0-cgu.0.rcgu.o
  • std-17a2ebd6a057695b.std.85d7ee4b9ed86dc5-cgu.0.rcgu.o
  • panic_abort-19abd3231a5a68e1.panic_abort.91c55d1e3b34cc5a-cgu.0.rcgu.o
  • object-1e8d9e6e76d7e39c.object.aaa832e42c2002c7-cgu.0.rcgu.o
  • memchr-6d4297d7c75d5124.memchr.566f1e27e3638d3-cgu.0.rcgu.o
  • addr2line-9777bb625cff662c.addr2line.5aaafcdf66320c0f-cgu.0.rcgu.o
  • gimli-b6ed3575ac511430.gimli.eca5a7624d30bf1d-cgu.0.rcgu.o
  • rustc_demangle-b3d82c0a728b7f64.rustc_demangle.ab3a3af5ca1e798f-cgu.0.rcgu.o
  • std_detect-18c4e37feaf6c455.std_detect.76f2520403c39475-cgu.0.rcgu.o
  • hashbrown-c94891b3ef521b49.hashbrown.c7d2780f994423f5-cgu.0.rcgu.o
  • rustc_std_workspace_alloc-ca3dd768d69d6b31.rustc_std_workspace_alloc.fe6178585bb60efc-cgu.0.rcgu.o
  • miniz_oxide-a169aad3aebf22c2.miniz_oxide.e45eec4987edcf44-cgu.0.rcgu.o
  • adler2-7b16a83ff4a53484.adler2.e9c6fc236776b423-cgu.0.rcgu.o
  • unwind-7eb8745742be4b14.unwind.bf12bf0cb896c334-cgu.0.rcgu.o
  • cfg_if-e48fc4c94d75b2db.cfg_if.aea63a901cfd2892-cgu.0.rcgu.o
  • libc-5d30e74617a8cf1d.libc.1983054eeb3af65e-cgu.0.rcgu.o
  • alloc-2fb2827490233b8f.alloc.608b2de49b3b58cb-cgu.0.rcgu.o
  • rustc_std_workspace_core-78f7dadf329575a3.rustc_std_workspace_core.3053220d9baf2c2a-cgu.0.rcgu.o
  • core-3bf6c94366e242a9.core.d42283a1bb95c7be-cgu.0.rcgu.o
  • compiler_builtins-efe8ec2187b9b6e0.compiler_builtins.b36c90c6e0608f99-cgu.0.rcgu.o

My best try so far is running:

RUSTFLAGS="-Clinker=clang -Clinker-plugin-lto=true -Clink-arg=-Wl,--no-rosegment -Clink-arg=-Wl,-z,pack-relative-relocs -Clink-arg=-Wl,-O1 -Copt-level=3 -Csplit-debuginfo=packed"
cargo build --lib --profile=dist

With the dist profile set to lto="fat". This allows us to do clang -flto -c -O3 examples/example.c from within limbo/sqlite to compile the example C file and then clang -static -flto -O3 example.o -L ../target/dist/ -llimbo_sqlite3 -ldl -lutil -lrt -lpthread -lm -lc to link together the object files.

If I run ./a.out I get result = hello, world.

This gets liblimbo_sqlite3.a in Linux to 51MB and a.out to 20MB. Running bare LLD (without setting any linker or anything) with fat LTO and no linker-plugin-lto gets the archive to 83MB and a.out to 18MB.

The only way I have found to go lower size is with nightly and build-std:

cargo clean +

RUSTFLAGS="-Zlocation-detail=none -Clink-arg=-Wl,--no-rosegment -Clink-arg=-Wl,-z,pack-relative-relocs -Clink-arg=-Wl,-O1 -Copt-level=3 -Csplit-debuginfo=packed --print=native-static-libs -Clinker-plugin-lto=true"
cargo +nightly build -Z build-std=std,panic_abort --lib --profile=dist

Which gets liblimbo_sqlite3.a down to 40MB and a.out to 18MB. Using mold with LLVMgold linker plugin yields no change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants