You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
According to @time and @time_imports, DocStringExtensions seems to recompile on every load, resulting in comparatively long load time (seems to vary a lot, but I've seen up to 75 ms). Now that very low level packages like SpecialFunctions depend on DocStringExtensions, this is becoming more noticeable. Is this inherent (recompilation) to the way DocStringExtensions works, or can we do something about this?
I spent a little more time looking at this one @oschulz@oscardssmith. Not sure this is actually being caused by anything that DocStringExtensions is doing...
julia> @time_imports using InitTest
1.0 ms InitTest
__init__ uncommented:
julia> @time_imports using InitTest
┌ 0.0 ms InitTest.__init__()
120.0 ms InitTest 98.78% compilation time
To me this doesn't look like anything to do with this package, but rather a Julia issue. I'd be grateful if anyone else is able to replicate the above behaviour.
Edit: What is written below seems to only be true on macOS.
This regressed in 1.11.3:
❯ julia +1.11.3 --project -q
julia> @time_imports using InitTest
┌ 0.0 ms InitTest.__init__()
63.8 ms InitTest 98.75% compilation time
❯ julia +1.11.2 --project -q
julia> @time_imports using InitTest
┌ 0.0 ms InitTest.__init__()
1.1 ms InitTest
Revisiting this with a bit of claude assistance this looks like this is a problem with the actual timing measurement. Claude:
For each package with an __init__, run_module_init in base/loading.jl calls print_time_imports_report_init to print the ┌ … __init__() line, and that function calls printstyled(...; color = :light_black). The kwcall specialisation behind it isn't in the sysimage, so it compiles the first time it runs. The print happens inside the parent package's load timer, so that compile time is charged to whichever package with an __init__ loads first. DocStringExtensions sits low in many dependency trees, so it usually loads first and gets the blame.
Some additions to the base Julia precompiles would likely solve it, or maybe moving the printing outside of the timing window.
I built a custom sysimage to verify it with an additional precompile for Base.print_time_imports_report_init(Base) and Base.print_time_imports_report(Base) to the tty_script generator and I saw the following kinds of numbers:
stock: 10–18 ms, 30–47% compilation
custom: about 4 ms, no compilation reported
@KristofferC, you know that code better, does the above correctly explain it?
Yes, that explanation is correct. The printing of the __init__() line happens inside the parent package's timing window, and the first print compiles printstyled for the stdout type, which gets charged to the first package with an __init__. The existing precompile for this (JuliaLang/julia#55729) ran with stdout redirected to devnull so it didn't cover TTY.
Fix in JuliaLang/julia#63755: the init lines are now printed after the package's timing is taken (so it is correct regardless of output type), and the TTY specializations are precompiled.
Activity
MichaelHatherly commentedon Aug 13, 2024
We should be able to do something about it.
oschulz commentedon Aug 13, 2024
Merci!
MichaelHatherly commentedon Aug 13, 2024
I thought perhaps it was some invalidations causing recompilation since
But SnoopCompile isn't giving me anything useful right now :)
oscardssmith commentedon Nov 20, 2024
I'm seeing much worse than this in some cases:
MichaelHatherly commentedon Nov 20, 2024
Any invalidations showing up in that particular case that can be traced back to
DocStringExtensions?MichaelHatherly commentedon Mar 25, 2025
I spent a little more time looking at this one @oschulz @oscardssmith. Not sure this is actually being caused by anything that
DocStringExtensionsis doing...First I commented out
DocStringExtensions.jl/src/DocStringExtensions.jl
Line 113 in f65720c
That's not surprising I would think.
So then I just swapped the body of the
__init__with a noop:That was under the assumption that it was calling
hook!that was causing the trouble. But that resulted inWhich, for me, is no different to the timings of the original
__init__:Bit weird. So then I just made a MWE package with just
And that resulted in the exact same behaviour:
__init__commented out:__init__uncommented:To me this doesn't look like anything to do with this package, but rather a Julia issue. I'd be grateful if anyone else is able to replicate the above behaviour.
oschulz commentedon Mar 25, 2025
Maybe we need one of the compiler experts on this ...
oscardssmith commentedon Mar 25, 2025
Gabriel is looking into this. Current suspicion is that it might be an issue with the timing.
KristofferC commentedon Mar 25, 2025
Edit: What is written below seems to only be true on macOS.
This regressed in 1.11.3:
Looks fixed on JuliaLang/julia#57871, probably due to this: JuliaLang/julia@56909d7.
MichaelHatherly commentedon Mar 25, 2025
Thanks @KristofferC.
KristofferC commentedon Mar 25, 2025
I am still not sure this is completely resolved.
archermarx commentedon Oct 16, 2025
Still hitting this on v1.12 on WSL
MichaelHatherly commentedon Oct 12, 2026
Revisiting this with a bit of claude assistance this looks like this is a problem with the actual timing measurement. Claude:
Some additions to the base Julia precompiles would likely solve it, or maybe moving the printing outside of the timing window.
I built a custom sysimage to verify it with an additional precompile for
Base.print_time_imports_report_init(Base)andBase.print_time_imports_report(Base)to the tty_script generator and I saw the following kinds of numbers:@KristofferC, you know that code better, does the above correctly explain it?
KristofferC commentedon Oct 12, 2026
It seems plausible at least and Claude is rarely wrong :)
KristofferC commentedon Oct 12, 2026
Claude:
Yes, that explanation is correct. The printing of the
__init__()line happens inside the parent package's timing window, and the first print compilesprintstyledfor thestdouttype, which gets charged to the first package with an__init__. The existing precompile for this (JuliaLang/julia#55729) ran with stdout redirected to devnull so it didn't coverTTY.Fix in JuliaLang/julia#63755: the init lines are now printed after the package's timing is taken (so it is correct regardless of output type), and the
TTYspecializations are precompiled.