Proposal: Run precompilation workloads at top-level instead of within package #51905
Labels
compiler:precompilation
Precompilation of modules
feature
Indicates new feature / enhancement requests
Currently, as part of the PkgImages feature introduced in julia 1.9 (and even in older versions of julia), users are encouraged to run snoop workloads at the end of the module definition, in order to capture compilation of julia generic functions that are invoked during that workload.
This introduces at least two problems:
__init__()
so some functionality may not work during package compilation? PrecompileTools.jl#32__init__()
the expectation is that the module's functions will not be called until the module is initialized, which we don't do during precompilation.Task cannot be serialized
error during precompilation disappeared in 1.9 #49513I would like to propose that we introduce an in-language supported mechanism to run a snoop workload, after a module is closed.
Syntactically, I think it could be as simple as moving the snoop / precompile statements to after the module, maybe by registering them in a callback that will be called when the runtime is finished closing the module. Something like:
Semantically, I propose that this would do something like the following:
deepcopy
of the module, which is what will be used for serialization.This allows us to separate the concerns of defining a module and running a workload to snoop compile it.
It allows us to ensure that the snoop workload doesn't accidentally introduce state into the module that is serialized, causing unexpected behaviors.
It allows us to be able to robustly ignore "dangling tasks", which preserves the behavior that pre-1.9 users have with PackageCompiler.
And the implementation doesn't seem too burdensome, and is free unless users use the new feature.
Thoughts?
The text was updated successfully, but these errors were encountered: