スキル一覧に戻る
gar-ai

rust-release-profile

by gar-ai

1🍴 0📅 2025年12月31日
GitHubで見るManusで実行

SKILL.md


name: rust-release-profile description: Configure release builds for maximum performance with LTO, optimizations, and binary stripping. Use for production deployments.

Release Profile

Optimize Rust builds for production performance and binary size.

Production Cargo.toml Profile

[profile.release]
opt-level = 3           # Maximum optimization
lto = true              # Link-time optimization (slower build, faster binary)
codegen-units = 1       # Single codegen unit (better optimization)
strip = true            # Strip debug symbols
panic = 'abort'         # Smaller binary, no unwinding

[profile.release-with-debug]
inherits = "release"
debug = true            # Keep debug info for profiling
strip = false

Optimization Levels

# opt-level options:
# 0 - No optimization (fastest compile)
# 1 - Basic optimization
# 2 - Default release optimization
# 3 - Maximum optimization (default for release)
# "s" - Optimize for size
# "z" - Optimize for size, disable loop vectorization

opt-level = 3   # Best performance
opt-level = "s" # Smallest binary with good performance
opt-level = "z" # Smallest binary
# LTO options:
# false - No LTO (fastest build)
# true/"fat" - Full LTO (slowest build, best performance)
# "thin" - Incremental LTO (good balance)

lto = true       # Best performance, slow build
lto = "thin"     # Good performance, faster build
lto = false      # Fastest build, no cross-crate optimization

Codegen Units

# Fewer units = better optimization, slower parallel compilation
codegen-units = 1    # Best optimization
codegen-units = 16   # Default, faster parallel builds

Debug Symbols

# For release builds
strip = true          # Remove all symbols
strip = "symbols"     # Remove symbols, keep sections
strip = "debuginfo"   # Remove debug info only
strip = "none"        # Keep everything

# Keep debug info for profiling
[profile.release-perf]
inherits = "release"
debug = true
strip = false

Panic Behavior

# 'unwind' - Default, allows catch_unwind, larger binary
# 'abort' - Smaller binary, faster, no unwinding

panic = 'abort'  # Production: smaller, faster
panic = 'unwind' # Development: catch panics, better debugging

Target-Specific Optimization

# Enable CPU-specific features
[build]
rustflags = ["-C", "target-cpu=native"]

# Or in .cargo/config.toml
[target.x86_64-unknown-linux-gnu]
rustflags = ["-C", "target-cpu=native"]

Profile for Different Use Cases

# Fast iteration during development
[profile.dev]
opt-level = 0
debug = true

# Quick release for testing
[profile.release-quick]
inherits = "release"
lto = false
codegen-units = 16

# Maximum performance
[profile.release]
opt-level = 3
lto = true
codegen-units = 1
strip = true
panic = 'abort'

# Profiling build
[profile.release-perf]
inherits = "release"
debug = true
strip = false

# Smallest binary
[profile.release-small]
inherits = "release"
opt-level = "z"
lto = true
codegen-units = 1
strip = true
panic = 'abort'

Workspace Settings

# In workspace Cargo.toml
[profile.release]
opt-level = 3
lto = true

# Override for specific packages
[profile.release.package.expensive-crate]
opt-level = 2  # Faster build for this crate

Build Commands

# Standard release build
cargo build --release

# With specific profile
cargo build --profile release-perf

# Check binary size
ls -la target/release/my-binary

# Strip binary manually (if not using strip = true)
strip target/release/my-binary

# Check for debug info
file target/release/my-binary

Measuring Impact

# Build time comparison
time cargo build --release
time cargo build --release --config 'profile.release.lto=false'

# Binary size comparison
cargo build --release
ls -la target/release/my-binary

cargo build --profile release-small
ls -la target/release-small/my-binary

# Performance comparison
hyperfine './target/release/my-binary' './target/release-quick/my-binary'

Guidelines

  • Use lto = true and codegen-units = 1 for production
  • Use strip = true and panic = 'abort' for smallest binaries
  • Use --profile release-perf with debug symbols for profiling
  • Use lto = "thin" for faster builds with good optimization
  • Test different opt-level values for your workload
  • Use target-cpu=native for deployment on known hardware

Examples

See hercules-local-algo/Cargo.toml for production profile.

スコア

総合スコア

60/100

リポジトリの品質指標に基づく評価

SKILL.md

SKILL.mdファイルが含まれている

+20
LICENSE

ライセンスが設定されている

+10
説明文

100文字以上の説明がある

0/10
人気

GitHub Stars 100以上

0/15
最近の活動

3ヶ月以内に更新がある

0/10
フォーク

10回以上フォークされている

0/5
Issue管理

オープンIssueが50未満

+5
言語

プログラミング言語が設定されている

+5
タグ

1つ以上のタグが設定されている

0/5

レビュー

💬

レビュー機能は近日公開予定です