[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-5509":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":23,"hasPages":23,"topics":25,"createdAt":10,"pushedAt":10,"updatedAt":35,"readmeContent":36,"aiSummary":37,"trendingCount":16,"starSnapshotCount":16,"syncStatus":38,"lastSyncTime":39,"discoverSource":40},5509,"min-sized-rust","johnthagen\u002Fmin-sized-rust","johnthagen","🦀 How to minimize Rust binary size 📦 https:\u002F\u002Fgithub.com\u002Fjohnthagen\u002Fmin-sized-rust","",null,"Rust",9778,247,109,11,0,4,14,38,16,81.98,"MIT License",false,"main",[26,27,28,29,30,31,32,33,34],"binary-size","cargo","containers","lto","no-std","rust","strip","upx","wasm","2026-06-12 04:00:25","# Minimizing Rust Binary Size\n\n[![GitHub Actions][github-actions-badge]](https:\u002F\u002Fgithub.com\u002Fjohnthagen\u002Fmin-sized-rust\u002Factions)\n\n[github-actions-badge]: https:\u002F\u002Fgithub.com\u002Fjohnthagen\u002Fmin-sized-rust\u002Fworkflows\u002Fbuild\u002Fbadge.svg\n\nThis repository demonstrates how to minimize the size of a Rust binary.\n\nBy default, Rust optimizes for execution speed, compilation speed, and ease of debugging\nrather than binary size, since for the vast majority of applications this is ideal. But\nfor situations where a developer wants to optimize for binary size instead, Rust provides\nmechanisms to accomplish this.\n\n# Build in Release Mode\n\n![Minimum Rust: 1.0](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.0-brightgreen.svg)\n\nBy default, `cargo build` builds the Rust binary in debug mode. Debug mode disables many\noptimizations, which helps debuggers (and IDEs that run them) provide a better debugging\nexperience. Debug binaries can be 30% or more larger than release binaries.\n\nTo minimize binary size, build in release mode:\n\n```bash\n$ cargo build --release\n```\n\n# `strip` Symbols from Binary\n\n![OS: *nix](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FOS-*nix-brightgreen.svg)\n![Minimum Rust: 1.59](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.59-brightgreen.svg)\n\nBy default on Linux and macOS, symbol information is included in the compiled `.elf` file. This\ninformation is not needed to properly execute the binary.\n\nCargo can be configured to\n[automatically `strip` binaries](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Fprofiles.html#strip).\nModify `Cargo.toml` in this way:\n\n```toml\n[profile.release]\nstrip = true  # Automatically strip symbols from the binary.\n```\n\n**Prior to Rust 1.59**, run [`strip`](https:\u002F\u002Flinux.die.net\u002Fman\u002F1\u002Fstrip) directly on\nthe `.elf` file instead:\n\n```bash\n$ strip target\u002Frelease\u002Fmin-sized-rust\n```\n\n# Optimize For Size\n\n![Minimum Rust: 1.28](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.28-brightgreen.svg)\n\n[Cargo defaults its optimization level to `3` for release builds][cargo-profile],\nwhich optimizes the binary for **speed**. To instruct Cargo to optimize for minimal binary\n**size**, use the `z` optimization level in\n[`Cargo.toml`](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Fmanifest.html):\n\n[cargo-profile]: https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Fprofiles.html#default-profiles\n\n```toml\n[profile.release]\nopt-level = \"z\"  # Optimize for size.\n```\n\n> [!NOTE]\n> In some cases the `\"s\"` level may result in a smaller binary than `\"z\"`, as explained in the\n> [`opt-level` documentation](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Fprofiles.html#opt-level):\n> \n> It is recommended to experiment with different levels to find the right balance for your project.\n> There may be surprising results, such as ... the `\"s\"` and `\"z\"` levels not being necessarily\n> smaller.\n\n# Enable Link Time Optimization (LTO)\n\n![Minimum Rust: 1.0](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.0-brightgreen.svg)\n\nBy default,\n[Cargo instructs compilation units to be compiled and optimized in isolation][cargo-profile].\n[LTO](https:\u002F\u002Fllvm.org\u002Fdocs\u002FLinkTimeOptimization.html) instructs the linker to optimize at the\nlink stage. This can, for example, remove dead code and often times reduces binary size.\n\nEnable LTO in `Cargo.toml`:\n\n```toml\n[profile.release]\nlto = true\n```\n\n# Dynamic Linking: Why It Doesn't Work\n\n![Minimum Rust: 1.0](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.0-brightgreen.svg)\n\nSome might suggest using [`prefer-dynamic`](https:\u002F\u002Fdoc.rust-lang.org\u002Frustc\u002Fcodegen-options\u002Findex.html#prefer-dynamic) for smaller binaries, but this approach has critical limitations:\n\n- **No stable ABI** - binaries break between Rust versions\n- **Deployment complexity** - requires exact library matches\n- **Community consensus** - static linking preferred for reliability\n\n# Reduce Parallel Code Generation Units to Increase Optimization\n\n[By default][cargo-profile], Cargo specifies 16 parallel codegen units for release builds.\nThis improves compile times, but prevents some optimizations.\n\nSet this to `1` in `Cargo.toml` to allow for maximum size reduction optimizations:\n\n```toml\n[profile.release]\ncodegen-units = 1\n```\n\n# Abort on Panic\n\n![Minimum Rust: 1.10](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.10-brightgreen.svg)\n\n> [!IMPORTANT]\n> Up to this point, the features discussed to reduce binary size did not have an\n> impact on the behaviour of the program (only its execution speed). This feature does\n> have an impact on behavior.\n\n[By default][cargo-profile], when Rust code encounters a situation when it must call `panic!()`,\nit unwinds the stack and produces a helpful backtrace. The unwinding code, however, does require\nextra binary size. `rustc` can be instructed to abort immediately rather than unwind, which\nremoves the need for this extra unwinding code.\n\nEnable this in `Cargo.toml`:\n\n```toml\n[profile.release]\npanic = \"abort\"\n```\n\n# Remove Location Details\n\n![Minimum Rust: Nightly](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-nightly-orange.svg)\n\nBy default, Rust includes file, line, and column information for `panic!()` and `[track_caller]`\nto provide more useful traceback information. This information requires space in the binary and\nthus increases the size of the compiled binaries.\n\nTo remove this file, line, and column information, use the unstable\n[`rustc` `-Zlocation-detail`](https:\u002F\u002Fgithub.com\u002Frust-lang\u002Frfcs\u002Fblob\u002Fmaster\u002Ftext\u002F2091-inline-semantic.md#location-detail-control)\nflag:\n\n```bash\n$ RUSTFLAGS=\"-Zlocation-detail=none\" cargo +nightly build --release\n```\n\n# Remove `fmt::Debug`\n\n![Minimum Rust: Nightly](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-nightly-orange.svg)\n\nWith the \n[`-Zfmt-debug`](https:\u002F\u002Fdoc.rust-lang.org\u002Fnightly\u002Funstable-book\u002Fcompiler-flags\u002Ffmt-debug.html) flag\nyou can turn `#[derive(Debug)]`and \n[`{:?}`](https:\u002F\u002Fdoc.rust-lang.org\u002Fstable\u002Fstd\u002Ffmt\u002Ftrait.Debug.html) formatting into no-ops. This\nwill ruin output of `dbg!()`, `assert!()`, `unwrap()`, etc., and may break code that unwisely\nrelies on the debug formatting, but it will remove derived `fmt` functions and their strings.\n\n```bash\n$ RUSTFLAGS=\"-Zfmt-debug=none\" cargo +nightly build --release\n```\n\n# Optimize `libstd` with `build-std`\n\n![Minimum Rust: Nightly](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-nightly-orange.svg)\n\n> [!NOTE]\n> See also [Xargo](https:\u002F\u002Fgithub.com\u002Fjaparic\u002Fxargo), the predecessor to `build-std`.\n[Xargo is currently in maintenance status](https:\u002F\u002Fgithub.com\u002Fjaparic\u002Fxargo\u002Fissues\u002F193).\n\n> [!NOTE]\n> Example project is located in the [`build_std`](build_std) folder.\n\nRust ships pre-built copies of the standard library (`libstd`) with its toolchains. This means\nthat developers don't need to build `libstd` every time they build their applications. `libstd`\nis statically linked into the binary instead.\n\nWhile this is very convenient there are several drawbacks if a developer is trying to\naggressively optimize for size.\n\n1. The prebuilt `libstd` is optimized for speed, not size.\n\n2. It's not possible to remove portions of `libstd` that are not used in a particular application\n   (e.g. LTO and panic behaviour).\n\nThis is where [`build-std`](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Funstable.html#build-std)\ncomes in. The `build-std` feature is able to compile `libstd` with your application from the\nsource. It does this with the `rust-src` component that `rustup` conveniently provides.\n\nInstall the appropriate toolchain and the `rust-src` component:\n\n```bash\n$ rustup toolchain install nightly\n$ rustup component add rust-src --toolchain nightly\n```\n\nBuild using `build-std`:\n\n```bash\n# Find your host's target triple.\n$ rustc -vV\n...\nhost: x86_64-apple-darwin\n\n# Use that target triple when building with build-std.\n# Add the =std,panic_abort to the option to make panic = \"abort\" Cargo.toml option work.\n# See: https:\u002F\u002Fgithub.com\u002Frust-lang\u002Fwg-cargo-std-aware\u002Fissues\u002F56\n$ RUSTFLAGS=\"-Zlocation-detail=none -Zfmt-debug=none\" cargo +nightly build \\\n  -Z build-std=std,panic_abort \\\n  -Z build-std-features=\"optimize_for_size\" \\\n  --target x86_64-apple-darwin --release\n```\n\nThe `optimize_for_size` flag provides a hint to `libstd` that it should try to use algorithms\noptimized for binary size. More information about it can be found in the \n[tracking issue](https:\u002F\u002Fgithub.com\u002Frust-lang\u002Frust\u002Fissues\u002F125612).\n\nOn macOS, the final stripped binary size is reduced to 51KB.\n\n# Remove `panic` String Formatting with `panic=immediate-abort`\n\n![Minimum Rust: Nightly](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-nightly-orange.svg)\n\nEven if `panic = \"abort\"` is specified in `Cargo.toml`, `rustc` will still include panic strings\nand formatting code in final binary by default.\n[An unstable `panic=immediate-abort` feature](https:\u002F\u002Fgithub.com\u002Frust-lang\u002Frust\u002Fpull\u002F146317)\nhas been merged into the `nightly` `rustc` compiler to address this.\n\nTo use this, repeat the instructions above to use `build-std`, but also pass\n[`-Zunstable-options -Cpanic=immediate-abort`](https:\u002F\u002Fdoc.rust-lang.org\u002Frustc\u002Fcommand-line-arguments.html#-z-set-unstable-options) and\n[`-Z build-std-features=`](https:\u002F\u002Fdoc.rust-lang.org\u002Fcargo\u002Freference\u002Funstable.html#build-std-features) (which will disable the default `backtrace` and `panic-unwind` features)\nto `rustc`.\n\n```bash\n$ RUSTFLAGS=\"-Zunstable-options -Cpanic=immediate-abort\" cargo +nightly build \\\n    -Z build-std=std,panic_abort \\\n    -Z build-std-features= \\\n    --target x86_64-apple-darwin --release\n```\n\nOn macOS, the final stripped binary size is reduced to 30KB.\n\n# Remove `core::fmt` with `#![no_main]` and Careful Usage of `libstd`\n\n![Minimum Rust: Nightly](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-nightly-orange.svg)\n\n> [!NOTE]\n> Example projects are located in the [`no_main`](no_main) folder.\n\nUp until this point, we haven't restricted what utilities we used from `libstd`. In this section\nwe will restrict our usage of `libstd` in order to reduce binary size further.\n\nIf you want an executable smaller than 20 kilobytes, Rust's string formatting code,\n[`core::fmt`](https:\u002F\u002Fdoc.rust-lang.org\u002Fcore\u002Ffmt\u002Findex.html) must\nbe removed. `panic=immediate-abort` only removes some usages of this code. There is a lot of other\ncode that uses formatting in some cases. That includes Rust's \"pre-main\" code in `libstd`.\n\nBy using a C entry point (by adding the `#![no_main]` attribute) , managing stdio manually, and\ncarefully analyzing which chunks of code you or your dependencies include, you can sometimes\nmake use of `libstd` while avoiding bloated `core::fmt`.\n\nExpect the code to be hacky and unportable, with more `unsafe{}`s than usual. It feels like\n`no_std`, but with `libstd`.\n\nStart with an empty executable, ensure\n[`xargo bloat --release --target=...`](https:\u002F\u002Fgithub.com\u002FRazrFalcon\u002Fcargo-bloat) contains no\n`core::fmt` or something about padding. Add (uncomment) a little bit. See that `xargo bloat` now\nreports drastically more. Review source code that you've just added. Probably some external crate or\na new `libstd` function is used. Recurse into that with your review process\n(it requires `[replace]` Cargo dependencies and maybe digging in `libstd`), find out why it\nweighs more than it should. Choose alternative way or patch dependencies to avoid unnecessary\nfeatures. Uncomment a bit more of your code, debug exploded size with `xargo bloat` and so on.\n\nOn macOS, the final stripped binary is reduced to 8KB.\n\n# Removing `libstd` with `#![no_std]`\n\n![Minimum Rust: 1.30](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.30-brightgreen.svg)\n\n> [!NOTE]\n> Example projects are located in the [`no_std`](no_std) folder.\n\nUp until this point, our application was using the Rust standard library, `libstd`. `libstd`\nprovides many convenient, well tested cross-platform APIs and data types. But if a user wants\nto reduce binary size to an equivalent C program size, it is possible to depend only on `libc`.\n\nIt's important to understand that there are many drawbacks to this approach. For one, you'll\nlikely need to write a lot of `unsafe` code and lose access to a majority of Rust crates\nthat depend on `libstd`. Nevertheless, it is one (albeit extreme) option to reducing binary size.\n\nA `strip`ed binary built this way is around 8KB.\n\n```rust\n#![no_std]\n#![no_main]\n\nextern crate libc;\n\n#[no_mangle]\npub extern \"C\" fn main(_argc: isize, _argv: *const *const u8) -> isize {\n    \u002F\u002F Since we are passing a C string the final null character is mandatory.\n    const HELLO: &'static str = \"Hello, world!\\n\\0\";\n    unsafe {\n        libc::printf(HELLO.as_ptr() as *const _);\n    }\n    0\n}\n\n#[panic_handler]\nfn my_panic(_info: &core::panic::PanicInfo) -> ! {\n    loop {}\n}\n```\n\n# Compress the binary\n\n> [!NOTE]\n> Up until this point, all size-reducing techniques were Rust-specific. This section describes\n> a language-agnostic binary packing tool that is an option to reduce binary size further.\n\n[UPX](https:\u002F\u002Fgithub.com\u002Fupx\u002Fupx) is a powerful tool for creating a self-contained, compressed\nbinary with no addition runtime requirements. It claims to typically reduce binary size by 50-70%,\nbut the actual result depends on your executable.\n\n```bash\n$ upx --best --lzma target\u002Frelease\u002Fmin-sized-rust\n```\n\n> [!WARNING]\n> There have been times that UPX-packed binaries have flagged heuristic-based antivirus software\n> because malware often uses UPX.\n\n# Tools\n\n- [`cargo-bloat`](https:\u002F\u002Fgithub.com\u002FRazrFalcon\u002Fcargo-bloat) - Find out what takes most of the\n  space in your executable.\n- [`cargo-llvm-lines`](https:\u002F\u002Fgithub.com\u002Fdtolnay\u002Fcargo-llvm-lines) - Measure the number and size\n  of instantiations of each generic function, indicating which parts of your code offer the highest\n  leverage in improving compilation metrics.\n- [`cargo-unused-features`](https:\u002F\u002Fgithub.com\u002FTimonPost\u002Fcargo-unused-features) - Find and prune\n  enabled but potentially unused feature flags from your project.\n- [`momo`](https:\u002F\u002Fgithub.com\u002Fllogiq\u002Fmomo) - `proc_macro` crate to help keeping the code footprint\n  of generic methods in check.\n- [Twiggy](https:\u002F\u002Frustwasm.github.io\u002Ftwiggy\u002Findex.html) - A code size profiler for Wasm.\n\n# Containers\n\nSometimes it's advantageous to deploy Rust into containers\n(e.g. [Docker](https:\u002F\u002Fwww.docker.com\u002F)). There are several great existing resources to help\ncreate minimum sized container images that run Rust binaries.\n\n- [Official `rust:alpine` image](https:\u002F\u002Fhub.docker.com\u002F_\u002Frust)\n- [mini-docker-rust](https:\u002F\u002Fgithub.com\u002Fkpcyrd\u002Fmini-docker-rust)\n- [muslrust](https:\u002F\u002Fgithub.com\u002Fclux\u002Fmuslrust)\n- [docker-slim](https:\u002F\u002Fgithub.com\u002Fdocker-slim\u002Fdocker-slim) - Minify Docker images\n- [dive](https:\u002F\u002Fgithub.com\u002Fwagoodman\u002Fdive) - A tool for exploring a container image and\n  discovering ways to shrink the size of the image.\n- [distroless](https:\u002F\u002Fgithub.com\u002FGoogleContainerTools\u002Fdistroless) - 2MB base image to run statically linked Rust program\n\n# References\n\n- [151-byte static Linux binary in Rust - 2015][151-byte-static-linux-binary]\n- [Why is a Rust executable large? - 2016][why-rust-binary-large]\n- [Tiny Rocket - 2018](https:\u002F\u002Fjamesmunns.com\u002Fblog\u002Ftinyrocket\u002F)\n- [Formatting is Unreasonably Expensive for Embedded Rust - 2019][fmt-unreasonably-expensive]\n- [Tiny Windows executable in Rust - 2019][tiny-windows-exe]\n- [Making a really tiny WebAssembly graphics demos - 2019][tiny-webassembly-graphics]\n- [Reducing the size of the Rust GStreamer plugin - 2020][gstreamer-plugin]\n- [Optimizing Rust Binary Size - 2020][optimizing-rust-binary-size]\n- [Minimizing Mender-Rust - 2020][minimizing-mender-rust]\n- [Optimize Rust binaries size with cargo and Semver - 2021][optimize-with-cargo-and-semver]\n- [Tighten rust’s belt: shrinking embedded Rust binaries - 2022][tighten-rusts-belt]\n- [Avoiding allocations in Rust to shrink Wasm modules - 2022][avoiding-allocations-shrink-wasm]\n- [A very small Rust binary indeed - 2022][a-very-small-rust-binary]\n- [The dark side of inlining and monomorphization - 2023][dark-side-of-inlining]\n- [Making Rust binaries smaller by default - 2024][making-rust-binaries-smaller-by-default]\n- [Tock Binary Size - 2024][tock-binary-size]\n- [Trimming down a rust binary in half - 2024][trimming-down-a-rust-binary-in-half]\n- [Reducing WASM binary size: lessons from building a web terminal - 2024][reducing-wasm-binary-size]\n- [`min-sized-rust-windows`][min-sized-rust-windows] - Windows-specific tricks to reduce binary size\n- [Shrinking `.wasm` Code Size][shrinking-wasm-code-size]\n\n[151-byte-static-linux-binary]: https:\u002F\u002Fmainisusuallyafunction.blogspot.com\u002F2015\u002F01\u002F151-byte-static-linux-binary-in-rust.html\n\n[why-rust-binary-large]: https:\u002F\u002Flifthrasiir.github.io\u002Frustlog\u002Fwhy-is-a-rust-executable-large.html\n\n[fmt-unreasonably-expensive]: https:\u002F\u002Fjamesmunns.com\u002Fblog\u002Ffmt-unreasonably-expensive\u002F\n\n[tiny-windows-exe]: https:\u002F\u002Fwww.codeslow.com\u002F2019\u002F12\u002Ftiny-windows-executable-in-rust.html\n\n[tiny-webassembly-graphics]: https:\u002F\u002Fcliffle.com\u002Fblog\u002Fbare-metal-wasm\u002F\n\n[gstreamer-plugin]: https:\u002F\u002Fwww.collabora.com\u002Fnews-and-blog\u002Fblog\u002F2020\u002F04\u002F28\u002Freducing-size-rust-gstreamer-plugin\u002F\n\n[optimizing-rust-binary-size]: https:\u002F\u002Farusahni.net\u002Fblog\u002F2020\u002F03\u002Foptimizing-rust-binary-size.html\n\n[minimizing-mender-rust]: https:\u002F\u002Fmender.io\u002Fblog\u002Fbuilding-mender-rust-in-yocto-and-minimizing-the-binary-size\n\n[optimize-with-cargo-and-semver]: https:\u002F\u002Foknozor.github.io\u002Fblog\u002Foptimize-rust-binary-size\u002F\n\n[tighten-rusts-belt]: https:\u002F\u002Fdl.acm.org\u002Fdoi\u002Fabs\u002F10.1145\u002F3519941.3535075\n\n[avoiding-allocations-shrink-wasm]: https:\u002F\u002Fnickb.dev\u002Fblog\u002Favoiding-allocations-in-rust-to-shrink-wasm-modules\u002F\n\n[a-very-small-rust-binary]: https:\u002F\u002Fdarkcoding.net\u002Fsoftware\u002Fa-very-small-rust-binary-indeed\u002F\n\n[dark-side-of-inlining]: https:\u002F\u002Fnickb.dev\u002Fblog\u002Fthe-dark-side-of-inlining-and-monomorphization\u002F\n\n[making-rust-binaries-smaller-by-default]: https:\u002F\u002Fkobzol.github.io\u002Frust\u002Fcargo\u002F2024\u002F01\u002F23\u002Fmaking-rust-binaries-smaller-by-default.html\n\n[tock-binary-size]: https:\u002F\u002Ftweedegolf.nl\u002Fen\u002Fblog\u002F126\u002Ftock-binary-size\n\n[trimming-down-a-rust-binary-in-half]: https:\u002F\u002Ftech.dreamleaves.org\u002Ftrimming-down-a-rust-binary-in-half\u002F\n\n[reducing-wasm-binary-size]: https:\u002F\u002Fwww.warp.dev\u002Fblog\u002Freducing-wasm-binary-size\n\n[min-sized-rust-windows]: https:\u002F\u002Fgithub.com\u002Fmcountryman\u002Fmin-sized-rust-windows\n\n[shrinking-wasm-code-size]: https:\u002F\u002Frustwasm.github.io\u002Fdocs\u002Fbook\u002Freference\u002Fcode-size.html\n\n# Organizations\n\n- [wg-binary-size]: Working group for improving the size of Rust programs and libraries.\n\n[wg-binary-size]: https:\u002F\u002Fgithub.com\u002Frust-lang\u002Fwg-binary-size\n\n# Legacy Techniques\n\nThe following techniques are no longer relevant for modern Rust development, but may apply to older\nversions of Rust and are maintained for historical purposes.\n\n## Remove Jemalloc\n\n![Minimum Rust: 1.28](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMinimum%20Rust%20Version-1.28-brightgreen.svg)\n![Maximum Rust: 1.31](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FMaximum%20Rust%20Version-1.31-brightgreen.svg)\n\n> [!IMPORTANT]\n> As of Rust 1.32,\n> [`jemalloc` is removed by default](https:\u002F\u002Fblog.rust-lang.org\u002F2019\u002F01\u002F17\u002FRust-1.32.0.html).\n> **If using Rust 1.32 or newer, no action is needed to reduce binary size regarding this\n> feature**.\n\n**Prior to Rust 1.32**, to improve performance on some platforms Rust bundled\n[jemalloc](https:\u002F\u002Fgithub.com\u002Fjemalloc\u002Fjemalloc), an allocator that often\noutperforms the default system allocator. Bundling jemalloc added around 200KB\nto the resulting binary, however.\n\nTo remove `jemalloc` on Rust 1.28 - Rust 1.31, add this code to the top of `main.rs`:\n\n```rust\nuse std::alloc::System;\n\n#[global_allocator]\nstatic A: System = System;\n```\n","该项目展示了如何最小化 Rust 二进制文件的大小。核心功能包括通过发布模式构建、移除符号信息、优化编译选项以减小体积以及启用链接时优化（LTO）等技术手段来实现这一目标。特别适合需要在资源受限环境中运行的应用场景，如嵌入式系统或对部署包大小有严格要求的 WebAssembly 项目。",2,"2026-06-11 03:03:42","top_language"]