From 221fcdd7b2557231ef29092c8306d0e9dee9f98b Mon Sep 17 00:00:00 2001 From: Mladen Kolar Date: Sat, 24 Oct 2026 04:10:30 +0400 Subject: [PATCH] A PrecompileTools workload for the estimators The first estimate of each kind compiled the whole three-stage estimator: 0.3 to 1.6 s for SymmetricNormal, AsymmetricNormal, SeparateNormal, ReducedNormal and the bootstrap. src/precompile.jl compiles them, in Float64, into the package image. In fresh processes their first calls take 0 to 56 ms on Julia 1.13 and 1.10; `using DiffPrecTest` takes as long as before on 1.13 and about 20 ms more on 1.10, and precompilation 3.5 s instead of 0.9 s. Co-Authored-By: Claude Opus 5.5 --- Project.toml | 2 ++ src/DiffPrecTest.jl | 7 +------ src/precompile.jl | 25 +++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) create mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index 501afc8..1924c69 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "0.3.0" [deps] CovarianceSelection = "fb9f034c-9bf8-4e47-a0a4-723273363029" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" ProximalBase = "0a755509-c5b1-5d6f-9b24-59bcda3c37a3" ProximalSolvers = "fc4971f5-6616-4709-9bfc-89a819252f6b" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" @@ -24,6 +25,7 @@ CovarianceSelection = "0.1" Ipopt = "1" JuMP = "1" LinearAlgebra = "1" +PrecompileTools = "1" ProximalBase = "0.5" ProximalSolvers = "0.1" Random = "1" diff --git a/src/DiffPrecTest.jl b/src/DiffPrecTest.jl index a01fce8..91effe6 100644 --- a/src/DiffPrecTest.jl +++ b/src/DiffPrecTest.jl @@ -647,11 +647,6 @@ function estimate( DiffPrecResultNormal(Δab, sqrt(v)) end - - - - - - +include("precompile.jl") end diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 0000000..a416c35 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,25 @@ +#################################### +# +# Precompilation +# +#################################### + +# The estimators' first calls, compiled into the package image. PrecompileTools +# runs this workload when the package is precompiled; the preference +# `precompile_workload = false` skips it. +using PrecompileTools: @setup_workload, @compile_workload + +@setup_workload begin + p, n = 5, 300 + Σy = [0.5^abs(i - j) for i in 1:p, j in 1:p] + X = randn(Xoshiro(1), n, p) + Y = randn(Xoshiro(2), n, p) * cholesky(Σy).U + @compile_workload begin + estimate(SymmetricNormal(), X, Y, 2, 1) + estimate(AsymmetricNormal(), X, Y, 2, 1) + estimate(SeparateNormal(), X, Y, 2, 1) + estimate(ReducedNormal(), X, Y, tril_index(p, 2, 1)) + straps, = bootstrap(X, Y; bootSamples = 2) + simulCIstudentized(straps, 0.95) + end +end