# Precompiling submodules

**URL:** https://discourse.julialang.org/t/precompiling-submodules/11683
**Category:** General Usage
**Created:** [June 14, 2018, 10:08pm UTC](https://discourse.julialang.org/t/precompiling-submodules/11683 "2018-06-14T22:08:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![tbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbo/32/9357_2.png) [@tbo](https://discourse.julialang.org/u/tbo)
#### Post date: [June 14, 2018, 10:08pm UTC](https://discourse.julialang.org/t/precompiling-submodules/11683/1 "2018-06-14T22:08:56Z")

</div>

Hi all,  
I’m having a hard time with ` __precompile__ ()`. I have a large project which consists of multiple submodules. To speed up the compilation process, I want to precompile some of the submodules, that would in theory support precompilation, and leave out the ones that do not. The overall project would not be precompilable.

```julia
__precompile__ (false)
module MyPackage
    __precompile__ ()
    module A
    ....
    end
    # __precompile__ (false)
    #module B
    #....
    #end
    using .A #, .B
end

```

This will, however, miserably fail, if ` __precompile__ (false)` appears even once at any place.  
Is there a way to use partial precompilation at a submodule level, or is precompilation itself it restricted to packages? The [docs](https://docs.julialang.org/en/v0.6.0/manual/modules/) are somewhat unclear about that, and do not distinguish between packages, modules and submodules.  
I want to avoid splitting the main Package into a dozen smaller packages, only to add somewhat decent support for precompilation.

Thanks for your help,  
Thomas

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [June 14, 2018, 10:17pm UTC](https://discourse.julialang.org/t/precompiling-submodules/11683/2 "2018-06-14T22:17:33Z")

</div>

I don’t think this is possible. But what exactly is making your submodules impossible to precompile? For the most part, this can be fixed by moving any run-time initialization into the ` __init__ ()` function.

---

<div class="post-metadata">

### Author: ![tbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbo/32/9357_2.png) [@tbo](https://discourse.julialang.org/u/tbo)
#### Post date: [June 14, 2018, 10:52pm UTC](https://discourse.julialang.org/t/precompiling-submodules/11683/3 "2018-06-14T22:52:14Z")

</div>

I should be able to fix many to all precompilation issues using ` __init__ ()`, however, this would involve additional complexity. Since I a) am lazy and b) wanted to keep the code simple I hoped for a small speedup by precompiling selected submodules.  
This would make a nice feature, if it should ever be added.

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [June 15, 2018, 11:31am UTC](https://discourse.julialang.org/t/precompiling-submodules/11683/4 "2018-06-15T11:31:38Z")

</div>

You say it’s a large project, in that case, wouldn’t it be better from a software engineering point of view (for unit testing, etc) to move the submodules out into their own files as normal modules?  
Then precompilation would just work.
