From c5ce7248b1e4e3c1ab5d7f79f0fa1298194d45a7 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Fri, 12 Dec 2025 16:45:55 +0100 Subject: [PATCH 1/5] Add a precompilation workload --- Project.toml | 4 ++- src/Aqua.jl | 2 ++ src/persistent_tasks.jl | 14 +++++++++-- src/precompile.jl | 55 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/precompile.jl diff --git a/Project.toml b/Project.toml index 03808671..bf5e755b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,14 +1,16 @@ name = "Aqua" uuid = "4c88cf16-eb10-579e-8560-4a9242c79595" -authors = ["Takafumi Arakaki and contributors"] version = "1.0.0-DEV" +authors = ["Takafumi Arakaki and contributors"] [deps] Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] Pkg = "1.6" +PrecompileTools = "1" Test = "<0.0.1, 1" julia = "1.6" diff --git a/src/Aqua.jl b/src/Aqua.jl index acc33a39..e1987f28 100644 --- a/src/Aqua.jl +++ b/src/Aqua.jl @@ -110,4 +110,6 @@ function test_all( end end +include("precompile.jl") + end # module diff --git a/src/persistent_tasks.jl b/src/persistent_tasks.jl index 77745b95..8379defa 100644 --- a/src/persistent_tasks.jl +++ b/src/persistent_tasks.jl @@ -111,8 +111,18 @@ end ) end # Precompile the wrapper package - cmd = `$(Base.julia_cmd()) --project=$wrapperdir -e 'push!(LOAD_PATH, "@stdlib"); using Pkg; Pkg.precompile(; io = devnull)'` - proc = run(cmd, stdin, stdout, stderr; wait = false) + currently_precompiling = @ccall(jl_generating_output()::Cint) == 1 + cmd = if currently_precompiling + # During precompilation we run a dummy command that just touches the + # status file to keep things simple. + code = """touch("$(escape_string(statusfile))")""" + `$(Base.julia_cmd()) -e $code` + else + `$(Base.julia_cmd()) --project=$wrapperdir -e 'push!(LOAD_PATH, "@stdlib"); using Pkg; Pkg.precompile(; io = devnull)'` + end + + cmd = pipeline(cmd; stdout, stderr) + proc = run(cmd; wait = false)::Base.Process while !isfile(statusfile) && process_running(proc) sleep(0.5) end diff --git a/src/precompile.jl b/src/precompile.jl new file mode 100644 index 00000000..450232e0 --- /dev/null +++ b/src/precompile.jl @@ -0,0 +1,55 @@ +using PrecompileTools: @compile_workload + +# Create a minimal fake package to test. Needs to be at the top-level because +# it's a module. +module _FakePackage +export fake_function +fake_function() = 1 +end + +@compile_workload begin + redirect_stdout(devnull) do + test_all( + _FakePackage; + ambiguities = false, + project_extras = false, + stale_deps = false, + deps_compat = false, + persistent_tasks = false) + end + + # Explicitly precompile the tests that need a real package module + precompile(test_ambiguities, (Vector{Module},)) + precompile(test_project_extras, (Module,)) + precompile(test_stale_deps, (Module,)) + precompile(test_deps_compat, (Module,)) + + # Create a fake package directory for testing persistent_tasks. We go to + # some effort to precompile this because it takes the longest due to Pkg + # calls and running precompilation in a subprocess. + mktempdir() do dir + project_file = joinpath(dir, "Project.toml") + write(project_file, """ + name = "AquaFakePackage" + uuid = "5a23b2e7-8c45-4b1c-9d3f-7a6b4c8d9e0f" + version = "0.1.0" + + [deps] + Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + + [compat] + Test = "1" + julia = "1" + """) + + srcdir = joinpath(dir, "src") + mkdir(srcdir) + write(joinpath(srcdir, "AquaFakePackage.jl"), "module AquaFakePackage end") + + # The meat of the compilation latency comes from this function. Running + # test_persistent_tasks() directly is more difficult because it takes a + # Module and then gets the package directory, and we don't want to load + # the fake package. + precompile_wrapper(project_file, 10, quote end) + end +end From 417a0fac7a1bb30e451576e2a70330a7a5bb9952 Mon Sep 17 00:00:00 2001 From: JamesWrigley Date: Fri, 12 Dec 2025 16:46:14 +0100 Subject: [PATCH 2/5] Make some inference improvements In particular to `find_stale_deps()`, which took about 600ms to compile. --- src/persistent_tasks.jl | 6 +++--- src/stale_deps.jl | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/persistent_tasks.jl b/src/persistent_tasks.jl index 8379defa..2daef554 100644 --- a/src/persistent_tasks.jl +++ b/src/persistent_tasks.jl @@ -84,8 +84,8 @@ function precompile_wrapper(project, tmax, expr) isdefined(Pkg, :respect_sysimage_versions) && Pkg.respect_sysimage_versions(false) try pkgdir = dirname(project) - pkgname = get(TOML.parsefile(project), "name", nothing) - if isnothing(pkgname) + pkgname = get(TOML.parsefile(project), "name", "")::String + if isempty(pkgname) @error "Unable to locate package name in $project" return false end @@ -111,7 +111,7 @@ end ) end # Precompile the wrapper package - currently_precompiling = @ccall(jl_generating_output()::Cint) == 1 + currently_precompiling = @ccall(jl_generating_output()::Cint) == 1 cmd = if currently_precompiling # During precompilation we run a dummy command that just touches the # status file to keep things simple. diff --git a/src/stale_deps.jl b/src/stale_deps.jl index ac7bad93..4ef1590c 100644 --- a/src/stale_deps.jl +++ b/src/stale_deps.jl @@ -48,9 +48,9 @@ function find_stale_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[]) found || error("Unable to locate Project.toml") prj = TOML.parsefile(root_project_path) - deps = PkgId[PkgId(UUID(v), k) for (k, v) in get(prj, "deps", Dict{String,Any}())] - weakdeps = - PkgId[PkgId(UUID(v), k) for (k, v) in get(prj, "weakdeps", Dict{String,Any}())] + deps::Vector{PkgId} = PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "deps", Dict())] + weakdeps::Vector{PkgId} = + PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "weakdeps", Dict())] marker = "_START_MARKER_" code = """ From 5d87c28f67d2678e6a29904c7a644617b96b60c0 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 25 Feb 2026 11:21:28 +0100 Subject: [PATCH 3/5] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index bf5e755b..306c6e5d 100644 --- a/Project.toml +++ b/Project.toml @@ -2,6 +2,7 @@ name = "Aqua" uuid = "4c88cf16-eb10-579e-8560-4a9242c79595" version = "1.0.0-DEV" authors = ["Takafumi Arakaki and contributors"] +version = "1.0.0-DEV" [deps] Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" From 94ca47c52f0a79f0a4d925b7b35c438793fc657d Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 25 Feb 2026 11:21:49 +0100 Subject: [PATCH 4/5] Apply suggestion from @github-actions[bot] Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- Project.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/Project.toml b/Project.toml index 306c6e5d..9392affc 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,5 @@ name = "Aqua" uuid = "4c88cf16-eb10-579e-8560-4a9242c79595" -version = "1.0.0-DEV" authors = ["Takafumi Arakaki and contributors"] version = "1.0.0-DEV" From d81d7ba75663b4b1a8a5a69eb8b76e36ca085913 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Wed, 25 Feb 2026 11:22:28 +0100 Subject: [PATCH 5/5] Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --- src/precompile.jl | 30 +++++++++++++++++------------- src/stale_deps.jl | 3 ++- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/precompile.jl b/src/precompile.jl index 450232e0..ca2a67c2 100644 --- a/src/precompile.jl +++ b/src/precompile.jl @@ -15,7 +15,8 @@ end project_extras = false, stale_deps = false, deps_compat = false, - persistent_tasks = false) + persistent_tasks = false, + ) end # Explicitly precompile the tests that need a real package module @@ -29,18 +30,21 @@ end # calls and running precompilation in a subprocess. mktempdir() do dir project_file = joinpath(dir, "Project.toml") - write(project_file, """ - name = "AquaFakePackage" - uuid = "5a23b2e7-8c45-4b1c-9d3f-7a6b4c8d9e0f" - version = "0.1.0" - - [deps] - Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - - [compat] - Test = "1" - julia = "1" - """) + write( + project_file, + """ +name = "AquaFakePackage" +uuid = "5a23b2e7-8c45-4b1c-9d3f-7a6b4c8d9e0f" +version = "0.1.0" + +[deps] +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +Test = "1" +julia = "1" +""", + ) srcdir = joinpath(dir, "src") mkdir(srcdir) diff --git a/src/stale_deps.jl b/src/stale_deps.jl index 4ef1590c..11d6473a 100644 --- a/src/stale_deps.jl +++ b/src/stale_deps.jl @@ -48,7 +48,8 @@ function find_stale_deps(pkg::PkgId; ignore::AbstractVector{Symbol} = Symbol[]) found || error("Unable to locate Project.toml") prj = TOML.parsefile(root_project_path) - deps::Vector{PkgId} = PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "deps", Dict())] + deps::Vector{PkgId} = + PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "deps", Dict())] weakdeps::Vector{PkgId} = PkgId[PkgId(UUID(v), k) for (k::String, v::String) in get(prj, "weakdeps", Dict())]