top | item 39743431

I reduced (incremental) Rust compile times by up to 40%

11 points| kapilsinha | 1 year ago |coderemote.dev

14 comments

order

nindalf|1 year ago

I think this is unlikely to gain traction. I say that no to discourage you, just to explain.

- The community has an instinctive distrust of closed source or a compiler from an untrusted source. If you’re familiar with the Trusting Trust attack you’ll understand why. People won’t send their code to you to compile, because they’re afraid of it being modified. People won’t use a closed source compiler, when an open source trusted one is available.

- Dev tools in every language ecosystem are almost always free, but sometimes even free tools don’t get adopted. Look the experience of the guy who built the mold linker(https://github.com/rui314/mold). Far superior to the state of art, improves incremental compiles a lot, widely applicable across ecosystems (C, C++, Rust), CPU architectures and Operating Systems. You don’t even have to modify your compiler, just need to point to his linker. He’s even giving it away for free for personal use. But still, almost no one uses it. The inertia of the established options is really high.

- It’s not complex enough. Think about the complexity involved in the cranelift backend. No one can seriously recreate the efforts of bjorn3. If we could have, we would have. But the idea idea here can be recreated, especially by the experts who already built incremental compilation into rustc.

- But if your solution is truly complex, like the parallel frontend, the burden of maintaining a fork would be too high. You’d have to spend all your time rebasing.

Again I’m not trying to discourage you, just stating the difficulties of making a business in the dev tools space. You would be better off contributing this excellent work to the community and trying a different tack.

kapilsinha|1 year ago

I appreciate this detailed explanation! To preface, I took on macro expansion caching because it was a clear solution for the slow builds I saw in some projects (taking the "project-specific" approach I mentioned in the blog). That said, my medium-term vision for CodeRemote isn't to develop a superior closed-source Rust compiler fork; instead, it is to provide remote tooling for faster development (i.e. bring small dev teams' tooling up closer to Google's level):

(a) pre-configured build servers, so a developer doesn't need to be equipped with the latest Mac to be functional

(b) shared cache within a developer team

(c) potential avenues in CI/CD, testing, etc.

I'd love to hear your thoughts on this goal! Does some aspect address a development pain point of yours? I also want to address your points above, and I agree with lots of them:

1. I agree that especially in the wider Rust community, closed source is not a long-term solution. For what it's worth, I have been considering making the source available -- though likely not with a super copyleft license, at least initially. Do you think making the source available would alleviate people's safety concerns?

2. I have thought about the mold/sold linker quite a bit, especially because the author changed his license on sold from a commercial license to MIT. And defaults are indeed very powerful (this is discussed in a recent change to strip debug info by default, https://kobzol.github.io/rust/cargo/2024/01/23/making-rust-b...) because most people aren't bothered to (or don't know to) change them. Generally one expects the defaults to be the best for the general case, but this is decidedly not true for Rust compiler settings.

I think there may be a difference, though, between catering to the general public and catering to specific users/clients. For the folks where link time is truly atrocious, I assume they make the effort to use mold (though again, there is good reason to be skeptical given that sold switched to an MIT license). I assume a similar willingness if/when someone's macro expansions are slow.

3. You're right, this macro caching feature is not complex! I'm sure someone like bjorn3 could code it up rather quickly. It does me no good trying to solo out-perform the rustc experts. But I think there is a lack of people improving the Rust dev experience. That's where I want to operate.

CJefferson|1 year ago

I’m not sending you my code to compile on your machine.

I understand wanting to make a successful product, and keepin your secret magic secure, but I’m afraid this just sets off so many alarm bells for me.

kapilsinha|1 year ago

Thanks for raising this. I hadn't anticipated this as a major concern. Is your main concern that you can't see the compiler code -- in which case would it help if the the source were available? Or is it even more than that, that you want to ensure that your build outputs are untampered and verifiably produced by a (deterministic) compiler?

I wonder though, would you trust remote CI/CD servers or Intel's proprietary C++ compiler (https://news.ycombinator.com/item?id=12363973)?

kapilsinha|1 year ago

Hi HN, I’m Kapil from CodeRemote. I am building Rust developer productivity tooling to speed up your edit-compile-run cycle. While I love Rust for its runtime performance and safety (not to mention its sweet syntactic sugar), I have long been frustrated with the resultant compile times.

This frustration hit a tipping point a few months ago, as I was building on a sluggish framework that made heavy use of code generation. From the Rust/Cargo/Rustc books and Rust community’s blog posts, I picked up and applied most of the standard tricks to speed up builds — but with only marginal improvement. Continued frustration led to me profiling and analyzing compile times, and soon I landed at the Rustc (compiler) source code…

I modified the compiler and implemented procedural macro caching, which has considerably sped up incremental builds for projects with macro-heavy dependencies. My fork of the compiler is still private as I’m still thinking through the licensing model; but if you’re interested in trying it out, please hit the “sign up” at the bottom of the blog. I am packaging it into a build/development server for a few Rust dev teams, and have already shared it with a few self-hosters! In this blog post, I discuss in detail my macro caching implementation and results. I’d love to hear your thoughts, and I’m happy to talk further about my compiler modifications.

periram|1 year ago

This directly addresses one of the core gripes about Rust - long compile times. Very nice to see efforts to address exactly that.

Would be quite interested to learn how this was achieved.

kapilsinha|1 year ago

Thanks! I go over some of the details of my procedural macro caching solution in the linked blog, and my code snippet there might be most informative.