PrecompileTools.jl

Reduce time-to-first-execution of Julia code
Popularity
128 Stars
Updated Last
11 Months Ago
Started In
April 2023

PrecompileTools

Stable Build Status Coverage

PrecompileTools allows you to reduce the latency of the first execution of Julia code. It is applicable for package developers and for "ordinary users" in their personal workflows.

To learn how to use PrecompileTools, see the documentation.

PrecompileTools and PackageCompiler

Particularly on Julia 1.9 and higher, PrecompileTools allows dramatic reduction in "time to first execution" (TTFX) without the need for user-customization. In this respect, it shares goals with (and performs similarly to) PackageCompiler.

Nevertheless, the two are not identical:

  • only PrecompileTools can be used by package developers to ensure a better out-of-box experience for your users
  • only PrecompileTools allows you to update your packages without needing to rebuild Julia
  • only PackageCompiler dramatically speeds up loading time (i.e., using ...) for all the packages

Here is a table summarizing the information.

Task Julia 1.9 + PrecompileTools PackageCompiler
Developers can reduce out-of-box TTFX for their users ✔️
Users can reduce TTFX for custom tasks ✔️ ✔️
Packages can be updated without rebuilding system image ✔️
Reduces time to load (TTL) ✔️

The difference in time to load arises because the system image can safely skip all the code-validation checks that are necessary when loading packages. Examples of the reduction in time to first execution and time to load can be found in the Julia 1.9 highlights blog post.

Inspecting the package precompile files

PkgCacheInspector provides insight about what's stored in Julia's package precompile files.

History (origins as SnoopPrecompile)

PrecompileTools is the successor to SnoopPrecompile. PrecompileTools differs in naming and in how one disables precompilation, but is otherwise a drop-in replacement.

This new package was created for several reasons:

  • PrecompileTools has become (directly or indirectly) a dependency of much of the Julia ecosystem, a trend that seems likely to grow with time. Therefore, this package is now hosted in the JuliaLang GitHub organization.
  • As Julia's own stdlibs migrate to become independently updateable (true for DelimitedFiles in Julia 1.9, with others anticipated for Julia 1.10), several of them would like to use PrecompileTools for high-quality precompilation. That requires making PrecompileTools its own "upgradable stdlib."
  • This package introduces the use of Preferences to make packages more independent of one another. Since this would have been a breaking change, it seemed like a good opportunity to fix other issues, too.

For more information and discussion, see the Discourse announcement post.

Required Packages