rustc-bloat

Analyze Rust binary bloat from monomorphization, large types, and macro expansion.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/fasterthanlime/.claude --skill rustc-bloat
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: rustc-bloat
Source: https://github.com/fasterthanlime/.claude/tree/main/skills/rustc-bloat
Command: npx skills add https://github.com/fasterthanlime/.claude --skill rustc-bloat

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Analyze Rust binaries to locate code bloat caused by monomorphization, large types, and macro expansion.

Core Features & Use Cases

  • Monomorphization analysis with cargo-llvm-lines to reveal hot copies
  • Large type detection using -Zprint-type-sizes
  • Macro expansion visibility with -Zunpretty=expanded
  • Bloat prioritization guidance for refactoring

Quick Start

Build the target and run the recommended commands, saving outputs to files, then inspect /tmp/llvm-lines.txt for top bloaters.

Frequently Asked Questions about rustc-bloat

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I identify what's causing my Rust binary to be oversized?

Rust binaries grow due to monomorphization, where generic code generates separate copies for each type. Use cargo-llvm-lines to reveal which functions produce the most machine code, then inspect -Zprint-type-sizes output to find large types contributing to bloat.

What's the best way to analyze monomorphization bloat in Rust?

Run cargo-llvm-lines on your binary to rank functions by code size, then cross-reference with -Zunpretty=expanded output to spot macro expansion contributors. Save all outputs to files and review the report identifying hotspots and optimization targets.

Can I use cargo-llvm-lines and type-size analysis on nightly Rust?

Yes. Monomorphization analysis requires nightly rustc flags: -Zprint-type-sizes for type detection and -Zunpretty=expanded for macro visibility. These unstable features enable the detailed inspection needed to locate code-generation bloat.

Why does my Rust compile time slow down with generic code?

Each distinct type instantiation of a generic function triggers separate code generation—monomorphization. Macro expansion amplifies this. Profiling with cargo-llvm-lines and macro inspection reveals which generics spawn the most copies, guiding refactoring decisions.

What should I check when binary size or compile time gets out of control?

First check for macro expansion contributors using -Zunpretty=expanded and scan llvm-lines output for duplicate function instances from monomorphization. Watch for large types flagged by -Zprint-type-sizes that multiply across instantiations.