Skip to content

[LiquidCortex.jl] GH#24 — Add precompilation workload hints for faster load times #24

Description

@rmems

Source

Synced / linked to GitHub for 1:1 mirror (2026-07-26).


Context

Julia 1.10+ supports PrecompileTools.jl workloads that precompile frequently-used methods at package install time, reducing first-call latency.

Currently, first call to SparseBrain(), step!(), or EnsembleBrain() triggers JIT compilation, which can take several seconds.

Goal

Add precompilation workloads for the most common operations.

Implementation

1. Add PrecompileTools dependency

[deps]
PrecompileTools = "aea7be01-6a6a-4083-8856-8d6e0d60b6f9"

2. Add workloads (src/LiquidCortex.jl)

using PrecompileTools

@compile_workload begin
    # Precompile SparseBrain constructor
    if _cuda_available[]
        brain = SparseBrain(20.0f0; n_in=8, n_out=4, name="precompile")
        u = CUDA.zeros(Float32, 8)
        step!(brain, u; inhibition=0.5f0)
        get_output(brain)
        
        ensemble = EnsembleBrain(; n_in=8, n_out=4)
        ensemble_step!(ensemble, u; inhibition=0.3f0)
        get_ensemble_output(ensemble)
    end
end

3. Keep workloads minimal

Precompilation runs at install time — keep it fast:

  • Use small dims (n_in=8, n_out=4) not full size
  • Only precompile the hot path (SparseBrain + step!)
  • Skip reference LSM (lazy-init, not critical path)

Acceptance criteria

  • PrecompileTools.jl added to deps
  • @compile_workload block added
  • using LiquidCortex load time measurably reduced
  • No regression in package test suite

Labels

performance, enhancement

Metadata

Metadata

Assignees

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions