I have a locally developed package Inherit.jl
. It has a __precompile__(true)
statement. When I open the package project, importing it does not show any compilation time:
K:\DevDocuments\fourthwave\pkg\Inherit>more Manifest.toml
# This file is machine-generated - editing it directly is not advised
julia_version = "1.10.10"
manifest_format = "2.0"
project_hash = "ae8820c6ea01bd8b2e229ea098dee154477e55fe"
[[deps.MacroTools]]
git-tree-sha1 = "1e0228a030642014fe5cfe68c2c0a818f9e3f522"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.16"
K:\DevDocuments\fourthwave\pkg\Inherit>julia --project -e "@time import Inherit"
0.008992 seconds (10.12 k allocations: 2.091 MiB)
K:\DevDocuments\fourthwave\pkg\Inherit>julia --project -e "@time import Inherit"
0.008357 seconds (10.12 k allocations: 2.091 MiB)
But when importing the same package from another project, which only contains Inherit.jl
, it always shows compilation time, and in fact loads slower (but without allocating more memory?):
K:\DevDocuments\fourthwave\pkg>more Manifest.toml
# This file is machine-generated - editing it directly is not advised
julia_version = "1.10.10"
manifest_format = "2.0"
project_hash = "c72befabb43ba325ce509143141e3a1ffe8b0b9a"
[[deps.Inherit]]
deps = ["MacroTools"]
path = "Inherit"
uuid = "341b8389-5eed-42ab-a01e-622c6bedf032"
version = "0.2.0"
[deps.Inherit.extensions]
TestExt = "Test"
[deps.Inherit.weakdeps]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
[[deps.MacroTools]]
git-tree-sha1 = "1e0228a030642014fe5cfe68c2c0a818f9e3f522"
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
version = "0.5.16"
K:\DevDocuments\fourthwave\pkg>julia --project -e "@time import Inherit"
0.013090 seconds (10.27 k allocations: 2.096 MiB, 37.25% compilation time)
K:\DevDocuments\fourthwave\pkg>julia --project -e "@time import Inherit"
0.013046 seconds (10.27 k allocations: 2.096 MiB, 38.16% compilation time)
The manifests look the same to me. What could be happening?
Inherit.jl
contains a TestExt package extension. When extension is loaded, the difference in load times between the two projects is even larger:
K:\DevDocuments\fourthwave\pkg\Inherit>julia --project -e "@time import Test"
0.020310 seconds (36.41 k allocations: 4.382 MiB)
K:\DevDocuments\fourthwave\pkg\Inherit>julia --project -e "@time begin import Test, Inherit end"
0.027284 seconds (46.56 k allocations: 5.289 MiB)
K:\DevDocuments\fourthwave\pkg\Inherit>julia --project -e "@time begin import Inherit, Test end"
0.025016 seconds (46.57 k allocations: 5.352 MiB)
vs
K:\DevDocuments\fourthwave\pkg>julia --project -e "@time import Test"
0.017926 seconds (36.33 k allocations: 4.375 MiB)
K:\DevDocuments\fourthwave\pkg>julia --project -e "@time begin import Test, Inherit end"
0.043615 seconds (133.40 k allocations: 11.632 MiB, 35.19% compilation time)
K:\DevDocuments\fourthwave\pkg>julia --project -e "@time begin import Inherit, Test end"
0.040809 seconds (133.60 k allocations: 11.643 MiB, 35.76% compilation time)
I believe this is indeed caused by extension mechanism. I have a pre-extension version of Inherit.jl
and it doesn’t exhibit this behavior.
I was able to reproduce the issue from this MWE itsdfish/PackageExtensionsExample.jl: A minimum working example of a package extension in Julia.
K:\DevDocuments\PackageExtensionsExample.jl>julia +1.11 --project -e "@time import PackageExtensionsExample"
0.001460 seconds (1.20 k allocations: 84.116 KiB)
K:\DevDocuments\PackageExtensionsExample.jl>julia +1.11 --project -e "@time import PackageExtensionsExample"
0.001321 seconds (1.20 k allocations: 84.069 KiB)
K:\DevDocuments\PackageExtensionsExample.jl>cd ..
K:\DevDocuments>julia +1.11 --project -e "@time import PackageExtensionsExample"
0.006718 seconds (2.46 k allocations: 150.663 KiB, 41.72% compilation time)
K:\DevDocuments>julia +1.11 --project -e "@time import PackageExtensionsExample"
0.004149 seconds (2.46 k allocations: 150.694 KiB, 63.95% compilation time)
Could be I’m reading too much into “compilation time”. It might not be the recompilation of package code, but compilation of methods to process the extension modules. For example:
K:\DevDocuments>julia --banner=no --project
... 你好我在 K:\DevDocuments
... aliases: pn = propertynames
... utilities available: @history, @cls, cls()
julia> @time import Inherit
0.013344 seconds (10.98 k allocations: 1.487 MiB, 36.63% compilation time)
julia> @time import PackageExtensionsExample
0.003583 seconds (1.63 k allocations: 126.219 KiB)
julia>
K:\DevDocuments>julia --banner=no --project
... 你好我在 K:\DevDocuments
... aliases: pn = propertynames
... utilities available: @history, @cls, cls()
julia> @time import PackageExtensionsExample
0.006131 seconds (2.48 k allocations: 181.250 KiB, 72.28% compilation time)
julia> @time import Inherit
0.007673 seconds (10.13 k allocations: 1.419 MiB)
Both modules use the extension mechanism, only the first loaded module shows “compilation time”. 