Open
Description
Precompiling a function which spawns a Task does not precompile the Task's function.
Normally, precompiling a function will also compile all statically reachable functions it could call. However, since the function itself doesn't invoke the anonymous function it creates for a Task it spawns, that function is not compiled.
Consider this small MRE ran with --trace-compile=stderr
:
julia> bar() = println("HI")
bar (generic function with 1 method)
julia> foo() = Threads.@spawn bar()
foo (generic function with 1 method)
julia> precompile(foo, ())
#= 6.6 =# precompile(Tuple{typeof(Main.foo)})
true
# Note that this _could_ have also compiled the lambda #foo##4#foo##5 which calls
# bar(), but it did not.
# Now, actually _calling_ the function, which causes the Task to get scheduled,
# does precompile that lambda when the Task is first executed:
julia> foo()
#= 4.6 =# precompile(Tuple{Main.var"#foo##4#foo##5"})
HI
Task (done) @0x00000001662fb2d0
This makes it difficult to precompile such functions during the Package Precompilation step, without actually running a snoop workload.
Thanks!