Stream: beginners

Topic: build speed is very slow?


view this post on Zulip Jared (Jan 01 2023 at 22:29):

I thought I'd use roc for some january generative art hacking, but the hello world compile time is looking like it'll be prohibitive. I'm seeing ~4 seconds to run roc dev, with nothing more than the basic "I'm a roc application" cli file from the tutorial. Is this expected? Do I have something wrong with my setup?

view this post on Zulip Brian Carroll (Jan 01 2023 at 23:09):

No, that doesn't sound normal at all. The compiler is so fast that sometimes I double check to see if it's showing me cached data, but it's not. Can you say more about your setup? Like is it a release or development build of the compiler itself?

view this post on Zulip Jared (Jan 02 2023 at 12:45):

@Brian Carroll

genuary on  main ➜ ./roc version
roc nightly pre-release, built from commit faaa466 on Sat Dec 17 09:07:43 UTC 2022

are the nightlies a dev build or something?

view this post on Zulip Jared (Jan 02 2023 at 12:49):

    Code Generation
           53.487 ms   Generate Assembly from Mono IR

Finished compilation and code gen in 87 ms

Produced a app.o file of size 4744

Finished linking in 3674 ms

wow lol what's up with linking

view this post on Zulip Jared (Jan 02 2023 at 12:49):

I'm on an intel MBP monterey fwiw

view this post on Zulip Brian Carroll (Jan 02 2023 at 12:51):

Jared said:

Brian Carroll

genuary on  main ➜ ./roc version
roc nightly pre-release, built from commit faaa466 on Sat Dec 17 09:07:43 UTC 2022

are the nightlies a dev build or something?

Nope! They're release builds.

view this post on Zulip Brian Carroll (Jan 02 2023 at 12:53):

Wow that link time is crazy. I'm not the best person to investigate but I'm sure someone will. Thanks for bringing it up!

view this post on Zulip Named-entity (Jan 02 2023 at 13:15):

For what it's worth linking is a bottleneck for some of the other languages that I explore.

view this post on Zulip Brian Carroll (Jan 02 2023 at 13:18):

Yes, that's true for us too, but this still seems well outside the normal range.

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 16:14):

Can you share a gist of the exact code you are running? I can take a look. Though there is a chance I won't be able to repro if it depends on running on an Intel Mac.

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 17:57):

Actually, I think I was able to repro. Though not to the same extent. On an M1 mac. linking takes about 1.6 seconds. Which is still super slow for a hello world app

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:31):

Ok. So I think I know the root cause, but I am not sure how we will want to go about fixing it.

For ld almost all of the time is spent in writing the output file: write output: 1.3 seconds ( 82.8%)
This is because the output file is about 32 megabytes.

The reason for this is 2 fold:

  1. we add the reqwest library to the cli platform (this pulls in a ton of dependencies like tokio).
  2. when rust generates a staticlib, it seems to link everything even if it isn't used (I have not figured out a way to stop this).

As such, the staticlib is about 32 megabytes. On the other hand, when directly linking an executable and cleaning up dead code, the total size is about 0.5 megabytes.

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:34):

Possible fixes:

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:47):

I think switching to from reqwest to ureq will be the easiest short term solution.

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:48):

though it only cuts from ~30MB to ~20MB...so not a big win actually....

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:48):

hmmm

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 18:50):

Oh, though it cuts link time from 1.6s to 0.6s for me. So that is a solid win.

view this post on Zulip Richard Feldman (Jan 02 2023 at 19:35):

how long is the link time on Linux with the surgical linker?

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 19:52):

~0ms

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 19:53):

That or the the timing is broken for the surgical linker. The timing seems to a be accurate, but I am not 100% convinced that includes dumping to file. That said, the entire process runs in ~200ms while compilation takes ~190ms. The last ~10ms would include loading the roc application itself and maybe dumping to file.

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 19:58):

Yeah, on my Linux machine, the legacy linker takes ~4s. So that matches the slow macos timing pretty well. It is linking ~35MB. The surgical linker only has to link ~7MB. Though obviously is faster for other reasons as well.

view this post on Zulip Richard Feldman (Jan 02 2023 at 22:48):

nice! So presumably surgical linking the fix we really want on macOS :big_smile:

view this post on Zulip Brendan Hansknecht (Jan 02 2023 at 23:15):

Yep

view this post on Zulip Jared (Jan 03 2023 at 03:06):

how far off is surgical for mac?

view this post on Zulip Brendan Hansknecht (Jan 03 2023 at 04:44):

That's a hard question to answer. Theoretically the code is pretty close, but:

  1. No one is actively working on it
  2. Connecting the final pieces and getting things working in practice can be a ton of time and debugging
  3. Documentation for macos linking is sparse and we could be missing some complicated piece or minor detail that makes everything a lot more painful to finish

Last updated: Jul 06 2025 at 12:14 UTC