SnoopCompile "snoops" on the Julia compiler, getting it to log the functions and argument-types it's compiling. By parsing the log file, you can learn which functions are being precompiled, and even how long each one takes to compile. You can use the package to generate "precompile lists" that reduce the amount of time needed for JIT compilation in packages.
SnoopCompile is not recommended for Julia beginners, and even experienced users may need several iterations to generate precompile scripts that work.
The easiest way to describe SnoopCompile is to show a snoop script, in this case for the
using SnoopCompile ### Log the compiles # This only needs to be run once (to generate "/tmp/colortypes_compiles.csv") SnoopCompile.@snoop "/tmp/colortypes_compiles.csv" begin using ColorTypes, Pkg include(joinpath(dirname(dirname(pathof(ColorTypes))), "test", "runtests.jl")) end ### Parse the compiles and generate precompilation scripts # This can be run repeatedly to tweak the scripts data = SnoopCompile.read("/tmp/colortypes_compiles.csv") pc = SnoopCompile.parcel(reverse!(data)) SnoopCompile.write("/tmp/precompile", pc)
After the conclusion of this script, the
"/tmp/precompile" folder will contain a number of
*.jl files, organized by package.
For each package, you could copy its corresponding
*.jl file into the package's
include it into the package:
module SomeModule # All the usual commands that define the module go here # ... followed by: include("precompile.jl") _precompile_() end # module SomeModule
There's a more complete example illustrating potential options in the
When calling the
@snoop macro, a new julia process is spawned using the function
Advanced users may want to tweak the flags passed to this process to suit specific needs.
This can be done by passing an array of flags of the form
["--flag1", "--flag2"] as the first argument to the
For instance, if you want to pass the
--project=/path/to/dir flag to the process, to cause the julia process to load the project specified by the path, a snoop script may look like:
using SnoopCompile SnoopCompile.@snoop ["--project=/path/to/dir"] "/tmp/compiles.csv" begin # ... statement to snoop on end # ... processing the precompile statements
Currently, precompilation does not cache functions from other modules; as a consequence, your speedup in execution time might be smaller than you'd like. In such cases, one strategy is to generate a script for your
base/userimg.jl file and build the packages (with precompiles) into julia itself. Simply append/replace the last two lines of the above script with
# Use these two lines if you want to add to your userimg.jl pc = SnoopCompile.format_userimg(reverse!(data)) SnoopCompile.write("/tmp/userimg_Images.jl", pc)
Users are warned that there are substantial negatives associated with relying on a
Pkg.update()will have no effect on packages that you've built into julia until you next recompile julia itself. Consequently, you may not get the benefit of enhancements or bug fixes.
1 day ago