This article provides an excellent overview of the latest in speed of optimizer vs quality of optimization . In particular, copy-and-patch compilation is still the fastest approach because it uses pre-compiled code, though leaves little room for optimization. Cranelift uses e-graphs to represent equivalence on the IR. This allows for more optimizations than the copy-and-patch approach. Of course, the most optimized o…
Cranelift code generation comes to Rust
21–30 of 117 posts
Re: Cranelift code generation comes to Rust
#22This article provides an excellent overview of the latest in speed of optimizer vs quality of optimization . In particular, copy-and-patch compilation is still the fastest approach because it uses pre-compiled code, though leaves little room for optimization. Cranelift uses e-graphs to represent equivalence on the IR. This allows for more optimizations than the copy-and-patch approach. Of course, the most optimized o…
Is there any literature or guidelines on what to do if I'm willing to spend effectively unlimited CPU cycles in return for a more optimized final output?
Also, program distillation: https://www.researchgate.net/publication/220989887_Distillat...
Re: Cranelift code generation comes to Rust
#23This article provides an excellent overview of the latest in speed of optimizer vs quality of optimization . In particular, copy-and-patch compilation is still the fastest approach because it uses pre-compiled code, though leaves little room for optimization. Cranelift uses e-graphs to represent equivalence on the IR. This allows for more optimizations than the copy-and-patch approach. Of course, the most optimized o…
Is there any literature or guidelines on what to do if I'm willing to spend effectively unlimited CPU cycles in return for a more optimized final output?
Re: Cranelift code generation comes to Rust
#24Re: Cranelift code generation comes to Rust
#25See https://www.reddit.com/r/rust/comments/1bhpfeb/vastly_improv...
Re: Cranelift code generation comes to Rust
#26Tried out the instructions from the article on a tiny Bevy project, and compared it to a "normal" build: > cargo build --release 23.93s user 22.85s system 66% cpu 1:09.88 total > cargo +nightly build -Zcodegen-backend 23.52s user 21.98s system 68% cpu 1:06.86 total Seems just marginally faster than a normal release build. Wonder if there is something particular with Bevy that makes this so? The author of the article…
Re: Cranelift code generation comes to Rust
#27[0] https://en.wikipedia.org/wiki/E-graph
[1] https://en.wikipedia.org/wiki/ESC/Java
[2] https://www.kindsoftware.com/products/opensource/escjava2/
Re: Cranelift code generation comes to Rust
#28Here are my build times when making a trivial change to a print-statment in a root function, comparing nightly dev vs adding cranelift + mold for rust-analyzer[0] (347_290 LoC) and gleam[1] (76_335 LoC):
$ time cargo build
Compiling rust-analyzer v0.0.0 (/home/user/repos/rust-analyzer/crates/rust-analyzer)
# nightly
Finished `dev` profile [unoptimized] target(s) in 6.60s
cargo build 4.18s user 2.51s system 100% cpu 6.650 total
# cranelift+mold
Finished `dev` profile [unoptimized] target(s) in 2.25s
cargo build 1.77s user 0.36s system 92% cpu 2.305 total
Compiling gleam v1.0.0 (/home/user/repos/gleam/compiler-cli)
# nightly
Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.69s
cargo build --bin gleam 3.02s user 1.74s system 100% cpu 4.743 total
# cranelift+mold
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.99s
cargo build --bin gleam 0.71s user 0.20s system 88% cpu 1.033 total
For me this is the most important metric and it shows a huge improvement. If I compare it to Go building Terraform[2] (371_594 LoC) it is looking promising. This is a bit unfair since it is the release build for Go and this is really nice in the CI/CD. Love Go compilation times and I thought it would be nice to compare with another language to show the huge improvements that Rust has made. $ time go build
go build 3.62s user 0.76s system 171% cpu 2.545 total
I was looking forward to parallel front-end[3], but I have not seen any improvement for these small changes.[0] https://github.com/rust-lang/rust-analyzer
[1] https://github.com/gleam-lang/gleam
[2] https://github.com/hashicorp/terraform
[3] https://blog.rust-lang.org/2023/11/09/parallel-rustc.html
*edit: code-comments & links + making it easier to see the differences