Skip to main content

Rust Cargo release build is not the fastest

By default, cargo build will build a debug binary at ./target/debug/filename, which is helpful for development/debug but without many binary optimizations, thus, runs slow.

When build with cargo build --release, it will build an optimized binary, which is ready for production:

--release                    Build artifacts in release mode, with optimizations

But it still not the fastest it can be.

Cargo profiles

Cargo has 4 builtin profiles: dev, release, test, and bench https://doc.rust-lang.org/cargo/reference/profiles.html which pre-defined build options. User can customize them in Cargo.toml, e.g:

[profile.dev]
opt-level = 1
debug = true

https://doc.rust-lang.org/cargo/reference/profiles.html#lto

Default profile.release sets lto = false.

[profile.release]
opt-level = 3
debug = false
split-debuginfo = '...'  # Platform-specific.
debug-assertions = false
overflow-checks = false
lto = false
panic = 'unwind'
incremental = false
codegen-units = 16
rpath = false

Set lto = true or lto = "fat" will

Performs "fat" LTO which attempts to perform optimizations across all crates within the dependency graph.

which makes build much slower, but the binary often faster 10-20% compare to lto = false. User may try lto = "thin" for faster build but the output still good comparable to lto = "fat"

"thin": Performs "thin" LTO. This is similar to "fat", but takes substantially less time to run while still achieving performance gains similar to "fat".

Reference

Happy building!

Comments

Popular posts from this blog

Tài liệu và hướng dẫn học Python

Để tiết kiệm thời gian, tốt nhất là đi học PyMI Updated: 130617 Sau đây là các tài liệu khuyên dùng: Vì nhiều lý do, nên học python2.7 tại thời điểm hiện tại (giờ là tháng 6/2013 - muốn biết tại sao thì tự tìm hiểu) python 3.5+ (giờ là tháng 2/2017) Chuẩn bị: 1. biết bật tắt máy 2. biết cài python 3. tập gõ 10 ngón - gõ 2 ngón hay 1 ngón cũng không sao, nhưng 10 ngón là cách dễ nhất để gõ nhanh nhất. Tài liệu - Nên dùng tài liệu tại trang chủ của Python làm chính, tham khảo thêm các tài liệu khác tại http://www.familug.org/2016/12/free-ebook.html Căn bản, mới học 1.1 Python PyMI.vn https://pymi.vn/tutorial/ 1.2. Python offical tutorial kết hợp làm bài tập trên HackerRank  (đề bài bằng tiếng Anh, nhưng Google translate 1 lúc cũng ra vì có nhiều ví dụ mẫu đi kèm). Học viên của Pymi.vn có rất nhiều học viên đã tự học với Learn Python the hard way nhưng chưa thấy ai thành công cả. Hai link dưới nên đọc sau khi đã nắm được những phần cơ bản của ngôn ngữ pytho...

The PyMiers

New FAMILUG