# Understanding building and compile times in DrRacket

**URL:** <https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450>\
**Category:** General\
**Tags:** build, compile\
**Created:** [December 28, 2024, 1:22am UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450 "2024-12-28T01:22:19Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 28, 2024, 1:22am UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/1 "2024-12-28T01:22:19Z")

</div>

I am on my first not completely trivial Racket project, and it was going really fine. Nothing too demanding, maybe twenty files or so, \< 100k source code, though it's meant to get bigger. I also use two libraries outside the code base, one is just my own goody bag, the other one is `racket-cas`.  
Builds were really fast after the initial one, updating any file never caused more than two seconds wait for anything to rebuild. I was really pleased with the easy progress. Then suddenly everything ground down to snail's pace. Updating a file could cause the build to take as much as 40"-1' to give me the repl. It's a real damp squib, and no fun at all - and I do this for fun, I am a hobbyist not a pro.

I can' really see anything that's changed suddenly, I don't have any cycles in my `require`s or anything silly like that. I also found that if I went and deleted all the compiled files in all three locations (codebase and two aforementioned libraries) then the next build would be fine for a while, giving me the usual two-second build delay. This does not last very long, however, before everything reverts to dead-slow. Even just exiting DrRacket - _while everything is going fine_ - makes the system revert to slow when restarting!!

So what I would like to know is what is the best and quickest way to learn about the build process, to see what I can optimize. I cannot really accept that recompiling one small file, forces a full system rebuild. Sure it works just dandy _once_ it's built, but it's a real palaver to get there and doesn't make for happy developing.

All ideas hints suggestions are warmly welcomed. Thanks.

* * *

BTW, I did discover that DrRacket actually compiles files as soon as you save them, you don't have to do a run for that to happen! That's really neat, I like it, but unfortunately it's only any good when the system is working fast. When it's slow I think it only adds to the problem and can even snag DrRacket.

---

<div class="post-metadata">

**Author:** ![notjack](https://avatars.discourse-cdn.com/v4/letter/n/e47774/32.png) [@notjack](https://racket.discourse.group/u/notjack)\
**Post date:** [December 28, 2024, 2:52am UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/2 "2024-12-28T02:52:24Z")

</div>

A few questions to help narrow down the issue:

- Are you experiencing this outside DrRacket too? DrRacket instruments programs so they run differently (read: slower) than they would at the command line.
- You talked about the build "taking forever to get you a REPL." The slowness might not be from _compiling_ code, but rather from _loading_ it - the latter occurs when starting up a program to get you a REPL. Does `raco setup` on your code take forever? Once your code _is_ compiled with `raco setup`, does loading it to get a REPL take forever? Slow compilation might be due to expensive macros, while slow loading might be due to expensive module loading graphs or expensive initialization code.
- What version and flavor of racket are you using?
- Are you using `#lang racket` or `#lang racket/base` in your code? The latter loads much faster than the former, at the expense of requiring you to declare your dependencies more explicitly.

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 28, 2024, 10:48am UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/3 "2024-12-28T10:48:06Z")

</div>

Thanks for the reply. In a bit more detail:

1. I am using DrRacket exclusively. I have not yet ventured beyond its bounds, that is what I am looking to do.
2. The program involved will end up being a kind of `#lang`, so the REPL will always be involved, even at the command line. I have one "main" or "environment" file, which is available to the user to bridge to all the rest of the libraries, editing anything other than this is only done to edit the system itself.  
Your explanation here re _loading_ time is useful. I have not used `raco setup` on its own yet. This is what I want to learn to do. Essentially I'm looking for docs/tutorials/cookbooks that will get me up to speed on this ASAP. (I have no expensive macros either - as yet)
3. Fresh new DrRacket 8.15 under Ubuntu.
4. **A-Ha!** This is something I can try out pretty quickly - I had a few files under `#lang racket/base` with full dependency descriptions, but got lazy and said sod it, I'll make everything `#lang racket` for now, and sort it out once it's cobbled together a bit better. I've only just put the build under an RCS too, so I can't look back, but I think that may be when it started playing up.

I guess what I'm really looking for are the docs on Racket without DrRacket.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [December 28, 2024, 11:05am UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/4 "2024-12-28T11:05:49Z")

</div>

It sounds as if you have a single file that takes long to compile (maybe you accidently wrote a macro with O(n^2) behaviour). That file will be recompiled each time you make changes either to that file - _or to files it depends on_.

You can use the module browser in DrRacket (see the "View" menu) to get an overview of your modules. Try systematically to make a cosmetic change to modules at the top of the tree (away from your main file) and see if you can find the file that provokes the long compile time.

Other things to do (mostly if you can't find the cause):  
disable background expansion (right click the circle in the lower, right corner of DrRacket).

Note: I accidently switched the meaning in the second sentence.

---

<div class="post-metadata">

**Author:** ![EmEf](https://avatars.discourse-cdn.com/v4/letter/e/53a042/32.png) [@EmEf](https://racket.discourse.group/u/EmEf)\
**Post date:** [December 28, 2024, 12:28pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/5 "2024-12-28T12:28:59Z")

</div>

Every summer/fall I create a project that comprises some 8000 to 10,000 loc. At some point it does get slower to load and reach the repl (for just running tests). What helps is

```
menu: Language —> Choose Language 
button: Details 
radio button: Populate “compiled” directories (for faster loading).  

```

If you have already turns this on, something else is slowing your code down and we may need more details.

(Background expansion is running in parallel. I doubt it has much of an impact.)

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 28, 2024, 1:16pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/6 "2024-12-28T13:16:53Z")

</div>

Thanks EmEf. It's already on.

I may put the project up on GitHub when it's a bit more viewable.  
In the meantime I've got a lot of reading to do about modules, compilation and raco 🙂

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 28, 2024, 5:45pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/7 "2024-12-28T17:45:28Z")

</div>

Well, I don't know what the heck I've done, but it seems that somehow I have brought the system back into order! Now I get the previous sub 3" builds on my rickety old laptop.

First I followed @notjack's advice and made sure all the files except the last one were `#lang racket/base`. Now the reproducible way to get it working is as follows:  
Delete all three `compiled` directories, including "my-libs" and "racket-cas". Run my project's main.rkt file. It builds more or less as expected in 40"-50" or so. Now the `compiled` files for "my-libs" and my project are present. However, the compiled files for `racket-cas` are ztill _not_ built. Dunno why. So I build these too, by loading running `raket-cas`'s repl.rkt file. After this everything runs as well as before, even if I edit files that depend on racket-cas, the build time stays the same sub 3".

One day I'm sure I'll understand what's going on, too... But for now I'm happy.  
I'll try to make a `raco` build, completely outside of DrRacket just to see how it goes.

Thanks for all the suggestions.

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 28, 2024, 5:59pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/8 "2024-12-28T17:59:13Z")

</div>

BTW, I did not need to turn off the background expansion for this to work.

_(Hey, where's the Discourse message edit button?)_

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [December 28, 2024, 9:03pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/9 "2024-12-28T21:03:48Z")

</div>

> [@AlexG](#):
>
> I also use two libraries outside the code base, one is just my own goody bag, the other one is `racket-cas`.

> [@AlexG](#):
>
> Now the `compiled` files for "my-libs" and my project are present. However, the compiled files for `racket-cas` are ztill _not_ built. Dunno why. So I build these too, by loading running `raket-cas`'s repl.rkt file. After this everything runs as well as before, even if I edit files that depend on racket-cas, the build time stays the same sub 3".

I vaguely recall that there's a heuristic somewhere with DrRacket about libraries from other collections (where you write `(require some-library)` instead of `(require "some-library.rkt")`. I think some layer of the system assumes under certain circumstances (but I don't recall off hand exactly what layer or which circumstances) doesn't check that those kinds of dependencies have up-to-date compiled code, and you can end up repeatedly recompiling things on the fly, or other kinds of bad states.

My practice is to use `raco setup some-library` when I've changed a dependency. Hopefully someone else can be more specific and accurate about why.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [December 28, 2024, 9:23pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/10 "2024-12-28T21:23:42Z")

</div>

> > ![](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/45/151_2.png "LiberalArtist") | [LiberalArtist](https://racket.discourse.group/u/liberalartist)  
> > December 28 |
> > 
> > - | - |
> 
> > 
> 
> My practice is to use `raco setup some-library` when I've changed a dependency. Hopefully someone else can be more specific and accurate about why.

This doesn't quite align with my own experience, but I mostly develop code in a (linked) package (even if I don't publish to the package server), so to compile my code I write

raco setup --pkgs my-package

and it does the rest. Even if I change a non-linked package dependency of my-package (such as gui-easy for Frosthaven Manager), all relevant modules get recompiled through this method.

PS I could also probably write `raco setup my-collect` in many cases, but for multi-collection packages that may not be what I want.

---

<div class="post-metadata">

**Author:** ![robby](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/robby/32/7_2.png) [@robby](https://racket.discourse.group/u/robby)\
**Post date:** [December 28, 2024, 11:08pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/11 "2024-12-28T23:08:06Z")

</div>

I think that DrRacket's automatic compilation will treat files differently at the package level of granularity. Specifically, if you have a file open in a particular package, it assumes it can write to those directories and thus tries to keep those .zo files up to date (assuming you have that option turned on) and it will use its own copies of the zo files (in compiled/drracket) in that case. If you don't have a file open in that package, then it will not do that.

I think that at some point we've come to the realization that this is not the best way to go but we aren't sure how to improve things more. Some of the relevant code is [here](https://github.com/racket/drracket/blob/master/drracket/drracket/private/eval-helpers-and-pref-init.rkt#L122-L142) and just generally in the following lines you can see how it configures `compiler/cm` if anyone has a good idea about how this should work and they want to try it out.

---

<div class="post-metadata">

**Author:** ![AlexG](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@AlexG](https://racket.discourse.group/u/AlexG)\
**Post date:** [December 29, 2024, 6:37pm UTC](https://racket.discourse.group/t/understanding-building-and-compile-times-in-drracket/3450/12 "2024-12-29T18:37:23Z")

</div>

Loads of info in this thread, I wonder if a better name for it would be:

> Understanding building and compile times **in DrRacket**

So as not to confuse with general bulding under raco, etc.  
If any mod thinks that would be a more suitable title, please feel free to change it.
