[ANN] Autoloads.jl

I am very happy to finally announce (the recently registered) Autoloads.jl, a package which has been about four years in the making!

Backstory

I don’t like repetition, being nagged, or being interrupted on my way to do things. All of which are reasons why being told “X is undefined” at in the REPL when reaching for a handy function from a utility package etc. is an experience I have wanted to minimise for a while. I come from the land of Emacs where packages use the magic comment ###;;;autoload to make it so that you can call a function before it’s defined, and so M-x do-useful-thing works regardless of whether or not its package was initially loaded.

Back when I did a survey of startup.jl files on GitHub (in 2022) and came across Fredrick Ekre’s “automatic tool loading”, it told me that it would be possible to do something similar in Julia, and so I souped it up and added a slightly fancier version to my Setup.jl (I turned my startup.jl into a package).

Lilith and I chatted about Julia configuration at JuliaCon 2023, and then the next year over on Zulip we talked more. This lead to Lilith creating the lovely BasicAutoloads.jl later in 2024 (Discourse announcement thread).

Meanwhile, I still wasn’t quite happy with what I had. You see, I had a vision where it would all just work, no thinking about what functions/macros I wanted to trigger what packages, etc. For the two years since, my ambition has been greater than my todo list can support, but the Autoloads package I envisioned still existed in my mind.

A couple of weeks ago, I thought I could probably dump the package in my mind into Claude Code with Opus 5.5, and it should be able to make it happen. It wasn’t perfect, but it was close enough that it’s just taken me about a week of mixed manual code-review-tweaking + prompting to finally realise the package in my mind.

But what does it do?

After you add using Autoloads to your startup.jl you’ll notice it adds a new Pkg.jl subcommand: pkg> autoloads, from which you can add packages. Here’s my current set:

(@v1.14) pkg> autoloads st
Global autoloads  ~/.julia/environments/v1.14/autoloads
  ✓ About             v1.0.4   2 exports
  ✓ CSV               v1.3.0       1 export,  11 public
  ✓ Chairmarks        v1.3.1       3 exports,  4 public
  ✓ ColorSchemes      v3.32.0     13 exports
  ✓ Colors            v0.13.4    143 exports
  ✓ Combinatorics     v1.1.0      43 exports
  ✓ DataFrames        v1.8.3      77 exports
  ✓ Distributions     v0.25.134  242 exports
  ✓ JSON              v1.13.4     11 exports, 18 public
  ✓ Primes            v0.5.7      17 exports
  ✓ SpecialFunctions  v2.9.2      77 exports
  ✓ StatsBase         v0.34.13   173 exports
  ✓ WhyNotEqual       v0.2.1       3 exports

All of the packages you register like this (pkg> autoloads add ...) are added to a sibling environment within the global environment’s workspace (not part of your global environment, but resolved together), and Autoloads.jl reads all the public + exported names and records them in a state file loaded at startup.

This means that you can then just use functions/variables/types from those packages as if they were already loaded and Autoloads will cleverly notice and load as required on-demand.

All of the benefit of a massive global environment eagerly loaded at startup, none of the drawbacks.

But wait, there’s more

Autoloads will also index the current project and its immediate dependencies, making them available as autoloads. You can see what it’s doing with pkg> autoloads st:

Project autoloads  ~/.julia/dev/KangarooTwelve/Project.toml
  ✓ KangarooTwelve   v1.0.0    2 exports
  ✓ Mmap             v1.11.0   2 exports
  ✓ Polyester        v0.7.19   4 exports
  ✓ PrecompileTools  v1.3.4    4 exports
  ✓ SIMD             v3.7.2   19 exports

This means when I’m working on my KangarooTwelve.jl package for example, I don’t even need to bother with using KangarooTwelve before calling functions from it, I can just open a fresh REPL and type @b k12("hello there") and @b will be automatically loaded from the global autoloads, and k12 from the KangarooTwelve project. No usings in sight.

But wait, there’s even more

While Autoloads only does automatic loading of packages you explicitly specify/have in the current project, it pays attention to every single package loaded in the REPL, which means that when you forget to add/import a package it can remind you which one(s) provide the name you just tried to use. E.g.

julia> heatmap
ERROR: UndefVarError: `heatmap` not defined in `Main`
Suggestion: check for spelling errors or missing imports.
Hint: heatmap is provided by packages that are not loaded:
  • pkg> add Makie
  • pkg> add UnicodePlots
  • pkg> add CairoMakie  (re-exports from Makie)

Performance and configuration

Autoloads works best when it sits in your startup.jl as a using Autoloads line. To help ensure this doesn’t get in the way of using the REPL, the package has been carefully structured and aggressively optimised to minimise latency. Even with the more involved initialisation (read a state file, set up autocompletions in the REPL, etc.) it should’t add more than a small handful of milliseconds to your startup.

There are a few ways that you can tweak Autoloads’ behavior (see the README) but it’s all managed via [preferences], for example to stop @spawn from Distributed from conflicting with Base.Threads, you can use this configuration:

[preferences.Autoloads]
packages.Distributed = {skip = ["@spawn"]}

Try it!

To me, Autoloads sits in a sweet-spot of automagical behaviour: it just makes it easier for me to do things in the REPL without the “ceremony” of actually thinking about what packages I want to load for what and typing out the required using statements :stuck_out_tongue:

Give it a shot! Let me know if you find it as useful as I do, and if you spot any misbehaviors (currently it’s tested to the level of “it works on my machine”)!

I’m anxious to try it out. Looks like it’s still stuck in the registration queue as of 2026-11-24T09:18:47-08:00

The registration PR was merged six hours ago. The time before it’s available on the package servers can vary, but if you’re impatient you can always install it by URL.