3 ms·
if this works would this make the rust compiler considerably smaller / faster?
by nijaar 2y ago
if this works would this make the rust compiler considerably smaller / faster?
- josephg 2y agoSmaller? Yes. Faster? Almost certainly not. It really doesn't make sense to optimize anything in a bootstrapping compiler. Usually the only code that will ever be compiled by this compiler will be rustc itself. And rustc doesn't need to run fast - just fast enough to recompile itself. So, the output also probably won't have any optimisations applied either.
- nijaar 2y agoif it is smaller, doesn't it mean that it has less code to execute hence should it be faster? Trying to understand better -- this is something completely new for me
- duped 2y agoNot necessarily, in fact one of the most important optimizations for compilers is inlining code (copy-pasting function bodies into call sites) which results in more code being generated (more space) but faster wallclock times (more speed). Most optimizations tradeoff size for speed in some way, and compilers have flags to control it (eg -Os vs -O3 tells most C compilers to optimize for size instead of speed). Where optimizing for size is optimizing for speed is when it's faster (in terms of wall clock time) for a program to compute data than to read it from memory, disk, i/o etc, because i/o bandwidth is generally much slower than execution bandwidth. That means the processor does more work, but it takes less time because it's not waiting for data to load through the cache or memory.
- nijaar 2y agogreat explanation. thank you!
- josephg 2y agoWhy would a program run faster just because it’s smaller?
- FullyFunctional 2y agoExample: this is a small program int main() { for(;;); }
- josephg 2y agoOh, I suppose I’m imagining two implementations that both do the same work. (Like two rust compilers). Eg, quicksort vs bubble sort. Quicksort is usually more code but faster. Or a linked list vs a btree. The linked list is less code, but the btree will be faster. Or substring search, with or without simd. The simd version will be longer and more complex, but run faster. Even in a for loop - if the compiler unrolls the loop, it takes up more code but often runs faster. If you have two programs that both do the same work, and one is short and simple, I don’t think that tells you much about which will run faster.
- kelnos 2y agoNo, this won't change rustc at all. The purpose of this project is to be able to bootstrap a current version of rustc without having to do hundreds of intermediate compilations to go from TinyCC -> Guile -> OCaml -> Rust 0.7 -> ...... Rust current. (Or bootstrap a C++ compiler to be able to build mrustc, which can compile Rust 1.56, which will give you Rust current after another 25 or so compilations.) Ultimately the final rustc you get will be more or less identical to the one built and distributed through rustup.
- nequo 2y ago> will be more or less identical What could cause differences between the bootstrapped rustc and rustup’s?
- comex 2y agoIn theory there shouldn’t be any. The official Rust builds, I believe, have one level of bootstrapping: the previous official build is used to build an intermediate build of the current version, which is then used to build itself. So the distributed binaries are the current version built with the current version. A longer from-source bootstrapping process should also end by building the current version with the current version, and that should lead to a bit-for-bit identical result. In practice, you’ll have to make sure the build configuration, the toolchain components not part of rustc itself (e.g. linker), and the target sysroot (e.g. glibc .so file) are close or identical to what the official builds are using. Also, while rustc is supposed to be reproducible, and thus free of the other usual issues with reproducible builds (like paths or timestamps being embedded into the build), there might be bugs. And I’m not sure if reproducibility requires any special options which the official builders might not be passing. Hopefully not. See also: https://github.com/rust-lang/rust/issues/75362 https://github.com/rust-lang/rust/issues/75362