実施した作業
Hello WorldのコンパイルまでBevyはまだ使わない
参考URL
プロジェクト作成とBevyの追加
プロジェクトを作る
cargo new bevy_project1
cd bevy_project1
BevyのDependencyを追加する
cargo add bevy
コンパイルオプションの調整
デバッグビルドの最適化オプションを推奨設定に合わせる
# Enable a small amount of optimization in the dev profile.
[profile.dev]
opt-level = 1
# Enable a large amount of optimization in the dev profile for dependencies.
[profile.dev.package."*"]
opt-level = 3
Hello, Worldの文字列を変えて再コンパイルにかかる時間は2秒程度
【参考】リリース用の設定など
wasmに最適化するためのコンパイルオプション
wasm-opt -Os --output output.wasm input.wasm
リリースビルド用のCargo.toml設定
Cargo.toml
# Enable more optimization in the release profile at the cost of compile time.
[profile.release]
# Compile the entire crate as one unit.
# Slows compile times, marginal improvements.
codegen-units = 1
# Do a second optimization pass over the entire program, including dependencies.
# Slows compile times, marginal improvements.
lto = "thin"
# Optimize for size in the wasm-release profile to reduce load times and bandwidth usage on web.
[profile.wasm-release]
# Default to release profile values.
inherits = "release"
# Optimize with size in mind (also try "z", sometimes it is better).
# Slightly slows compile times, great improvements to file size and runtime performance.
opt-level = "s"
# Strip all debugging information from the binary to slightly reduce file size.
strip = "debuginfo"
繰り返しコンパイル時間を短縮するための設定についてのメモ
ダイナミックリンク
実行時に次のオプション(ダイナミックリンク)を入れると早くなるらしい
cargo run --features bevy/dynamic_linking
次のコマンドを実行しておくと自動的にオプションを付けてくれるようになる
cargo add bevy -F dynamic_linking
ゲーム公開時にはダイナミックリンクのオプションを外すことをお勧めされている
Shipping your game with dynamic linking enabled is not recommended because it requires you to include libbevy_dylib alongside your game, it prevents certain optimizations, and can increase the size of your game. If you remove the dynamic_linking feature, your game executable can run standalone.
他
- リンカをLLDに変える
- Nightly Rust Compiler
- Cranelift
- Generic Sharing
- Improve Runtime Performance (Optional)