# Faster Precompiles with Monorepo?

**URL:** https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986
**Category:** General Usage
**Tags:** question, precompilation
**Created:** [May 30, 2024, 8:47pm UTC](https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986 "2024-05-30T20:47:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)
#### Post date: [May 30, 2024, 8:47pm UTC](https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986/1 "2024-05-30T20:47:49Z")

</div>

At work we have a monorepo with all our Julia code in a place like `~/company/src/`, and making any change to the codebase triggers precompilation again whenever I start a new notebook or REPL:

```julia
julia> using MyModule
Precompiling MyModule
  1 dependency successfully precompiled in 99 seconds. 631 already precompiled.

```

I would like to solve this, while still using a single git repository. Here are some things I’ve tried:

- Making a sysimage with `PackageCompiler` for all the external dependencies (but not our code). This made a big difference on older versions of Julia, but doesn’t seem to matter anymore, perhaps because precompilation is now the default?
- Using `Preferences` to try and disable precompilation. This gives me a `LocalPreferences.toml` file. It triggered a big recompilation of seemingly every dependency, however, `using MyModule` still has a long precompilation every time

```julia
[MyModule]
precompile_workload = false

```

- Running commands using `SnoopPrecompile` and `PrecompileTools`, which seemed to have the same effect as `Preferences`
- Putting ` __precompile_false__ ` at the top of my main file. Also didn’t seem to do anything.
- Using Revise. That helps the symptom, but I often need to spin up new REPLs/notebooks, and Revise can’t help there

Is there anything else I can do? Is there another piece of configuration I need to set up to disable precompilation? Alternatively, is there a way to make it faster while maintaining the monorepo?

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [May 31, 2024, 1:48am UTC](https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986/2 "2024-05-31T01:48:27Z")

</div>

You said monorepo, but do you also have a MonoModule? Could you split your git repository into multiple smaller packages and then reexport all the symbols from a MetaModule package? They could all still be in the same repository, but they each would have their own Project.toml.

If you do not want to manage a bunch of Project.toml files, you try the [implicit package directory approach](https://docs.julialang.org/en/v1/manual/code-loading/#Package-directories).

Another thought is if you had tried `julia --pkgimages=no` in combination with the system image of all external dependencies.

My final question in all of this is “What is happening during precompilation?”. `precompile_workload = false` will affect code in a `@compile_workload` section. Do you have top-level code executing outside a `@compile_workload` section? Is there a lot happening in your `MyModule. __init__ ()`?

---

<div class="post-metadata">

### Author: ![Satvik](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/satvik/32/20486_2.png) [@Satvik](https://discourse.julialang.org/u/Satvik)
#### Post date: [May 31, 2024, 9:37am UTC](https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986/3 "2024-05-31T09:37:59Z")

</div>

1. We currently have a MonoModule, but we could change that. However, all of the guides I found for setting up multiple packages required using git submodules, which we’ve had terrible experiences with. The implicit package directory approach looks like it might avoid that, I’ll try it out.

2. I tried this and it attempts to precompile my module, then crashes with a segfault:

```julia
[3216] signal (11.1): Segmentation fault
in expression starting at REPL[1]:1
Allocations: 7251341 (Pool: 7243658; Big: 7683); GC: 12
Segmentation fault (core dumped)

```

The sysimage does run without `--pkgimages=no`, though it still precompiles.

1. There’s no ` __init__ ()`, and I don’t currently have a sense of whether there’s a specific part of the codebase that’s generating these long precompiles. We do have a fair number of functions defined through macros, though I’m not sure if that should make a difference.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [May 31, 2024, 2:03pm UTC](https://discourse.julialang.org/t/faster-precompiles-with-monorepo/114986/4 "2024-05-31T14:03:40Z")

</div>

See this other thread perhaps:

> [@Usage of subdirectories to store multiple packages in a single repo](https://discourse.julialang.org/t/usage-of-subdirectories-to-store-multiple-packages-in-a-single-repo/55534/2):
>
> Many/most of these questions can probably be answerd by this: Packages in subdirectories are just regular packages. They just happen to live in the same git repo. Yes they need to be packages on their own with Project.toml, src/Package.jl entrypoint etc. Probably this structure makes the most sense: $ tree . . ├── PackageA │ ├── Project.toml │ └── src │ └── PackageA.jl └── PackageB ├── Project.toml └── src └── PackageB.jl 4 directories, 4 files or perhaps $ tree …
