wasm-slim
Rust CLI tool for automated WASM binary size optimization
๐ฏ Goal
Reduce WASM bundle sizes by 60%+ without requiring deep optimization expertise.
Before:
# Manual optimization (complex, error-prone)
# Result: Maybe 500KB โ 200KB if you know what you're doing
After:
# Output: 60% size reduction, zero config โจ
๐ Research Foundation
Built on production learnings from real-world WASM optimization projects:
Warp.dev (Dec 2024)
- 21.4MB โ 8MB (62% reduction)
- Technique: Asset management + compiler optimization
- Blog post
Additional Validation
- Internal projects validating dependency optimization techniques
- Proven patterns for feature flag optimization and LTO configuration
- Real-world verification of 60%+ size reduction strategies
๐ Features (Planned)
- โ Automated Cargo.toml optimization
- โ Integrated build pipeline (wasm-bindgen + wasm-opt + wasm-snip)
- โ Dependency analysis and suggestions
- โ Size profiling with twiggy integration
- โ CI/CD integration with size budgets
- โ Template system for common frameworks (Yew, Leptos, Dioxus)
- โ NEW: Nightly Rust build-std support (10-20% additional reduction)
๐ Advanced: Nightly Rust Optimizations
For maximum size reduction, use nightly Rust with the build-std feature:
# Switch to nightly toolchain
# Build with automatic build-std configuration
What is build-std?
- Rebuilds the standard library with your project's optimization settings
- Enables
panic_immediate_abortfeature (eliminates panic infrastructure) - Provides an additional 10-20% size reduction on top of other optimizations
- Based on Leptos binary size guide
How it works:
wasm-slimdetects your nightly toolchain automatically- Creates
.cargo/config.tomlwith optimal build-std settings - Subsequent builds use the custom-built standard library
Requirements:
- Nightly Rust toolchain (install with
rustup default nightly) - Opt-in feature (automatically enabled when nightly is detected)
Note: On stable Rust, wasm-slim will provide a tip about nightly benefits.
๐ฆ Installation
From crates.io
From source
๐ Examples
The examples/ directory contains production-tested scripts and workflows:
- size-tracking-script.sh: Drop-in CI script for size budget enforcement
- cargo-toml-optimizations.toml: Battle-tested Cargo.toml configurations
- twiggy-analysis-workflow.md: Step-by-step WASM size analysis guide
See examples/README.md for details.
๐ Documentation
- Architecture Guide - System design and module organization
- Performance Guide - Optimization techniques and profiling
- Benchmark Guide - Running and writing performance benchmarks
- Testing Guide - Contributing test guidelines
๐งช Quality
- Tests: Comprehensive test suite with 1000+ tests (unit, integration, doc tests)
- Benchmarks: Multiple benchmark suites with regression detection
- CI/CD: Automated testing, security audits, performance tracking
- Coverage: 95%+ test coverage across all modules
๐ง Development
Prerequisites
Required:
- Rust 1.86+ (MSRV)
cargo(comes with Rust)
For full integration tests:
# Install WASM target
# Install wasm-bindgen-cli (required for build integration tests)
Note: Unit tests (~355 tests) run without any additional tools. Integration tests that exercise the build pipeline will skip gracefully if wasm-bindgen-cli is not installed.
Running Tests
# Run all tests (unit + integration, some may skip without tools)
# Run only unit tests (no external tools required)
# Run integration tests (requires wasm-bindgen-cli)
# Run with coverage
Test Requirements
- Unit tests: No external dependencies
- Integration tests: Some tests require
wasm-bindgen-clifor full pipeline testing - Doc tests: No external dependencies
- Benchmarks: No external dependencies
Integration tests will display a helpful message if tools are missing:
โ ๏ธ Skipping test: wasm-bindgen-cli not found in PATH
Install with: cargo install wasm-bindgen-cli
๐ค Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
Ways to contribute:
- Report bugs and suggest features
- Improve documentation
- Add test coverage
- Share WASM optimization experiences
๐ License
MIT License - see LICENSE file for details
๐ Acknowledgments
- Warp.dev team for publishing their WASM optimization journey
- Rust WASM community for tooling (twiggy, wasm-bindgen, wasm-opt)
- Internal projects that validated optimization techniques
๐ฌ Contact
Issues and questions: GitHub Issues
Version: 0.1.0 (Pre-1.0 - API may change)