Stream: beginners

Topic: Compile time performance


view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:48):

I have a 1,300 loc project which is taking ~20s to compile in my M1 MAX. This is pretty high, right?
The performance really degraded recently as I added more types. It was taking ~8s when I was at 1,074 loc.

view this post on Zulip Folkert de Vries (Mar 20 2023 at 14:49):

are you using a nightly build? or did you compile the compiler yourself?

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:49):

Nightly from the 17th

view this post on Zulip Folkert de Vries (Mar 20 2023 at 14:50):

ok. what sort of project is this?

view this post on Zulip Folkert de Vries (Mar 20 2023 at 14:51):

there are some things in type checking that are slow. it does not surprise me, but it is disappointing that we run into issues so quickly

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:51):

I ran roc build --time and it looks like code gen takes 7s. I'm a little confused reading the other sections as the times don't seem to add up to the totals.

view this post on Zulip Folkert de Vries (Mar 20 2023 at 14:51):

yeah. Timing is weird because we run on multiple threads

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 14:51):

can you share the --time info?

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:51):

sure

view this post on Zulip Folkert de Vries (Mar 20 2023 at 14:51):

code gen time should not be influenced by adding more type annotations though

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 14:52):

can you also share how long just a check takes?

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:53):

https://gist.github.com/agu-z/8eb15cb9f536a6bb9fcfeda55f9b963e

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:54):

@Ayaz Hafiz check takes ~1.2s

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 14:54):

can you share --time for roc check?

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 14:56):

some of this is LLVM but it is a bit worrisome that some of these modules are taking ~0.5 seconds to check and >1second to generate the Roc-internal IR for.

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 14:56):

roc check --time https://gist.github.com/agu-z/456d02af60c236a9c0bba4a41639233a

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 15:03):

ok. can you share this project?

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 15:04):

Yep, it's a private repo now, but give me a min

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 15:10):

https://github.com/agu-z/roc-pg

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 15:10):

It depends on my fork of basic-cli with sockets support: https://github.com/agu-z/roc-basic-cli/tree/sockets-support

view this post on Zulip Agus Zubiaga (Mar 20 2023 at 15:16):

A bunch of things lack type annotations and I'm using _ all the time while I'm figuring out how I want to do error handling. Maybe that has something to do with it.

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 15:17):

I think that's unlikely, type annotations (or lack thereof) don't really change the computational complexity of the compiler

view this post on Zulip Brendan Hansknecht (Mar 20 2023 at 16:21):

I think this somehow blows up specialization and the amount of copies of llvm ir we generate.

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 18:17):

can you drop the flame graph in this chat @Brendan Hansknecht ? It might be off if it's not run with --max-threads=1

view this post on Zulip Brendan Hansknecht (Mar 20 2023 at 18:18):

roc-pg.svg

view this post on Zulip Brendan Hansknecht (Mar 20 2023 at 18:18):

Was run with --max-threads=1

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 18:24):

okay, we are spending all of our time doing occurs checks (checking and fixing recursive types)

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 18:25):

in lambda sets, which makes sense

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 18:26):

I have some ideas on how to deal with this. we added a bunch of caching to deal with this problem half a year ago but we can add even more

view this post on Zulip Brendan Hansknecht (Mar 20 2023 at 18:39):

Do you now why it generates so much llvm ir?

view this post on Zulip Ayaz Hafiz (Mar 20 2023 at 18:40):

probably the large # of lambda sets, not sure though

view this post on Zulip Agus Zubiaga (Apr 06 2023 at 20:24):

CleanShot-2023-04-06-at-17.23.092x.png
Not bad @Ayaz Hafiz!

view this post on Zulip Agus Zubiaga (Apr 06 2023 at 20:27):

Oh, and check now takes 20ms instead of 10s!

view this post on Zulip Ayaz Hafiz (Apr 06 2023 at 21:07):

the unreasonable effectiveness of a good properly placed cache :exhale:

view this post on Zulip Richard Feldman (Apr 07 2023 at 01:12):

even more impressive, the part of the build that was so slow went from over 100K ms to under 100ms, so...3 orders of magnitude improvement. :rocket: :rocket: :rocket:

view this post on Zulip Richard Feldman (Apr 07 2023 at 01:13):

which is relevant because the other 2 parts that make up almost all of that 6 seconds are linking and code generation, and the WIP surgical linking and dev backend projects should massively reduce those too

view this post on Zulip Ayaz Hafiz (Apr 07 2023 at 04:35):

as a bit of anecdotal history: the last time we ran into something like this (~half a year ago) it took three weeks of full time effort (and one week of despair where nothing worked), and several major redesigns, to fix the problem. So this time around, the relatively simple effort, and knowledge of where else our gaps lie, is IMO a positive sign for the quality and maturity of the compiler.

view this post on Zulip Ayaz Hafiz (Apr 07 2023 at 04:39):

moreover - it is exciting that folks like @Agus Zubiaga are getting the opportunity to stress the compiler in ways like this that actually expose where the faults are, and show how far the language has gotten!


Last updated: Jul 06 2025 at 12:14 UTC