Base.precompile appears not to work

Precomplation does not fully compile the code only partially (there is a good reason for this, which I don’t know). Thus there is still time needed to fully compile the code. This is what you see. If you want to completely compile everything then you need to create a custom system image, see https://github.com/JuliaLang/PackageCompiler.jl.

You can see the effect of pre-compilation by turning it off:

 >> julia --compiled-modules=no
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.2 (2020-09-23)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> @time using Plots; @time plot(rand(10)); @time plot(rand(10))
WARNING: using Plots.GR in module Main conflicts with an existing identifier.
 55.193715 seconds (86.28 M allocations: 4.281 GiB, 3.10% gc time)
  3.356667 seconds (4.55 M allocations: 229.180 MiB, 2.77% gc time)
  0.000789 seconds (2.62 k allocations: 160.070 KiB)

vs with precompile

>> julia                      
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.5.2 (2020-09-23)
 _/ |\__'_|_|_|\__'_|  |  
|__/                   |

julia> @time using Plots; @time plot(rand(10)); @time plot(rand(10))
  9.253607 seconds (14.31 M allocations: 856.438 MiB, 3.50% gc time)
  2.318332 seconds (3.22 M allocations: 166.281 MiB, 1.86% gc time)
  0.000696 seconds (2.76 k allocations: 164.273 KiB)

So, it impacts both the load-time during using and the time to execute plot.

Last note that most likely the precompile statement for plot(rand(10)) is already contained within Plots.jl; precompile statements is not something the user needs to do (unless one is missing).

2 Likes