# Choosing what to precompile as a package author

**URL:** <https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705>\
**Category:** General Usage\
**Created:** [February 16, 2023, 2:17am UTC](https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705 "2023-02-16T02:17:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 16, 2023, 2:17am UTC](https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705/1 "2023-02-16T02:17:38Z")

</div>

The native code caching in 1.9 is amazing, but as a package author its sometimes hard to navigate the precompile-time / run-time tradeoff and decide what to precompile. In my case if I precompile “pretty much everything one might need” it takes a pretty painful 5min (but then ofc TTFX is amazing). But in certain contexts alot of that may be overkill. For example, if I myself am doing some active development requiring restarts, I might want nothing precompiled, or if eg my package is being used in a project that knows it will do Float32 but never Float64, they could halve the precompile time.

Right now I’m thinking I have a Preferences.jl preference in my package which specifies how much (or how little) to precompile. The advantages I see is that it gives the user some control, and by keeping the precompile directives in _my_ package (rather than e.g. an enclosing monorepo), it will cut down some on the repetition of that 5min.

I’m wondering if this sounds like a reasonable thing to do? Or if anyone else has faced this and has thoughts on what works well and what doesnt? Thanks.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [February 16, 2023, 8:05am UTC](https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705/2 "2023-02-16T08:05:34Z")

</div>

Rather than use Preferences to control precompilation, would it work to document for users how to create their own custom Startup.jl packages? [Question about using SnoopPrecompile - #9 by tim.holy](https://discourse.julialang.org/t/question-about-using-snoopprecompile/88227/9)

---

<div class="post-metadata">

**Author:** ![marius311](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marius311/32/3953_2.png) [@marius311](https://discourse.julialang.org/u/marius311)\
**Post date:** [February 16, 2023, 8:40am UTC](https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705/3 "2023-02-16T08:40:26Z")

</div>

Thanks, yea, that’s definitely the most flexible option I suppose, but in terms of imagining writing the README, for my approach its something like “run `MyPackage.set_preference!("precompile", "Float32, Float64")`” and select what you want, whereas for that theyre "generate a package in environment X, open the file, edit it to contain particular code Y, remember to import your package), it seems a fair bit more complex.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [February 16, 2023, 4:34pm UTC](https://discourse.julialang.org/t/choosing-what-to-precompile-as-a-package-author/94705/4 "2023-02-16T16:34:50Z")

</div>

Nothing wrong with using Preferences for this purpose. (Much better than an `ENV` variable.)
