Back to News
Advertisement
Advertisement

⚡ Community Insights

Discussion Sentiment

82% Positive

Analyzed from 1035 words in the discussion.

Trending Topics

#zig#build#bun#more#https#rust#compilation#com#something#compile

Discussion (30 Comments)Read Original on HackerNews

anaqin1 day ago
Good write up! I was hoping it was going to conclude with the author getting buns zig build way faster than Rusts but a good deep dive nevertheless
lalitmaganti1 day ago
Having spent ~3 weeks of evenings and weekends on this, I was a bit burned out to keep trying to optimize especially because all of this code is just a dead end anyway...

The fix seemed to be to split up Bun's Zig module into ~100 pieces just like they've done on Rust but how representative that would have been on anything Bun might of shipped is very much in question!

pfg_about 23 hours ago
The issue with splitting up Bun's Zig module is that Rust is designed for multiple crates compiling separate objects and linking them together in the end, but for Zig you would need to manually export and import C abi functions and you can't make use of language features like slices, generics, non-extern structs, and others anymore. In Zig, every module is compiled in the same compilation unit. Even the standard library is compiled in the same unit as your app.
hbbioabout 13 hours ago
Zig 0.17 should solve this with incremental compilation. What you said will stay but should only apply for the first compilation.
bloaf1 day ago
The next questions in my head are:

A) Is there any performance penalty on the compiled result due to being optimized in separate pieces

B) If not, why isn't the optimizer smart enough to split them up internally and optimize in parallel?

lalitmaganti1 day ago
> A) Is there any performance penalty on the compiled result due to being optimized in separate pieces

AFAIK, the answer to this is no but only if LTO is doing a good job and actually optimizing well across object files.

> B) If not, why isn't the optimizer smart enough to split them up internally and optimize in parallel?

I think there was another comment by someone more knowledgable in Zig that this is something which is being discussed by the Zig compiler team.

anaqin1 day ago
Your post went into way more depth than I was expecting when I first opened up it up. You clearly spent a lot of time on it and I appreciated reading the tale so thank you. Given all the drama around AK / Bun, it just would have been so funny to see someone not involved in the project solve one of the main motivations for the move to rust.

I believe there is a fork of bun from 1.3 that a different community is maintaining. I wonder if they’ve been able to get the compile times down by modularizing the build?

listicabout 22 hours ago
> I believe there is a fork of bun from 1.3 that a different community is maintaining.

There is Buz effort to do this which might be worked at, behind the scenes: https://github.com/jazzzooo/buz

(I'm looking forward to looking into Zig)

rahkiin1 day ago
Can you force a non-parallel build of those rust crates to make the comparison fairer?
lalitmaganti1 day ago
Nice idea! I was only thinking about "how could I make Zig more efficient", I didn't even consider making Rust more similar to Zig.

I added a Python script wrapping rustc which serializes all rustc invocations for bun_* crates; you can find the recoridng at [1]. Turns out it only increased the build by 1 minute! So clearly my intuitition that it was just crate parallelism was not correct.

One more confounding factor though is that rustc is parallelised while Zig's compiler is not (yet). So it's still possible that might be the reason.

[1] https://buildprof.lalitm.com/#!/?url=https%3A%2F%2Fblogexamp...

Retro_Dev1 day ago
this! - the reason Zig defaults to one semantic analysis thread is due to current (to be improved) limitations; some ideas for Zig also will require one compilation unit - the restricted function pointers proposal being a good example: https://github.com/ziglang/zig/issues/23367

The bun team tried to parallelize Zig's semantic analysis a while back - and it DID compile about 4x as fast... YET the builds were no longer deterministic, which is a hard requirement for lots of things. More effort will need to be spent here than naively adding a thread pool. Hopefully Zig's Sema.zig gets faster, but Rust is also super slow at compiling and needs to improve. Oh - one last thing to note, Zig has very fast debug compilation and incremental compilation, it's a real nice thing to work with that you simply can't approach in most other languages right now.

saghmabout 8 hours ago
"Fairer" seems like a strange characterization if what you're actually telling to measure is real-world compile times. If two people were running a race and one had better, trying to make the race "fairer" by forcing that one to run with the same form as the other pretty silly.
t435621 day ago
It's like Electric Insight, which was a fantastic if proprietary tool.

There's an enormous amount of analysis you can do with tools like this from estimating how much faster the build would be with more cores (i.e. is it worth adding more) to things like a diff of one build against another: why is one build bad and the other good - what tasks had different parameters or weren't in both builds?

lalitmaganti1 day ago
Diffing is something I definitely want to support. I've filed https://github.com/LalitMaganti/buildprof/issues/12 to add support for this, I have ideas!
emelskiabout 21 hours ago
Hey, I created ElectricInsight! It's nice to hear somebody besides me remembers it fondly.
t43562about 11 hours ago
I know you did!

It's quite odd how everything gets re-invented isn't it? N years ago I didn't think that javascript would ever have a "build time" problem but I've already been asked if I can write a "filesystem" for one well known web platform and I wondered if they wanted something like EFS. I obviously said no because I didn't feel like trying to pretend that I write filesystems three times a year.

dmpyatyiabout 12 hours ago
just a comment to support post :) Incredible work!!!
jiehongabout 16 hours ago
Nice!

What would the macOS equivalent be?

lalitmagantiabout 11 hours ago
There's an open bug for adding macOS support to buildprof: https://github.com/LalitMaganti/buildprof/issues/2

If you mean "how would I implement it without ptrace", there are a few options but likely the Endpoint Security API [1] would be the way to go. But it's not too great because it needs full disk access and root, neither of which I would be particularly happy accepting :(

[1] https://developer.apple.com/documentation/endpointsecurity

flimflamm1 day ago
It would be interesting to see what would be good input for LLMs to do the optimizations / trials on that automatically. Is the visual representation best or something else?
lalitmaganti1 day ago
It's actually trivially easy to add a "automated report" feature to buildprof due to its architecture (just a few SQL queries on top of Perfetto's trace processor). And I'm sure AI could hill climb the build time based on this.

But I still think the visual view is invaluable for human understanding and for the "why is this even happening" problems which I think AI is still bad at seeing.

Conlectus1 day ago
This is just how hacker news is now, huh?

“I did this cool useful thing”

“Great! Please describe how I can get a machine to replace you.”

crefizabout 10 hours ago
yh mate sorry for living in a capitalist society
quietrasterabout 14 hours ago
build time visualizers always reveal something embarrassing in the graph. did the bun team engage with your findings, curious if the bottlenecks were known internally
lalitmagantiabout 11 hours ago
They did not, I did cc Jarred on X but not reached out anything beyond that!
xcc3641about 21 hours ago
Full LTO on the WebKit link is the serial part. Does your visualizer split link time from codegen?
lalitmagantiabout 21 hours ago
Yes the whole article is about exactly that :)

You can also use --compiler-traces to understand the inside of the linking process as well; these annotations are provided by lld.

applfanboysbgonabout 24 hours ago
Excellent write-up, love to see profiling work on compile times. I have some rudimentary tooling I threw together myself but nothing that looks as comprehensive and insightfully presented as this, I'll be giving it a try!
applfanboysbgonabout 19 hours ago
Update: this tool allowed me to almost immediately diagnose a compile time mystery I encountered yesterday that I hadn't yet been able to identify with my own tools. Great work!