In one of my packages I tried to lower import
times, so I added a couple of typical usage examples in a “precompile” function. Something like
function _my_precompile()
# my "typical use case" code
...
end
function _precompile_()
ccall(:jl_generating_output, Cint, ()) == 1 || return nothing
_my_precompile()
# precompile directives from SnoopCompile
...
end
_precompile_()
However, in the presence of the _my_precompile
, benchmarks of my code show thousands of allocations in code that should not be allocating. On the other hand, after I remove _my_precompile
, all these spurious allocations disappear, as they should.
I am deeply confused. How can precompilation functions that do not change the code lead to different allocation behavior during use of the library?
I do not have a MWE yet, but if you want to verify this behavior for yourself, here is the commit which removes the precompilation. Before it the benchmarks show allocations, after it most allocations disappear. The benchmark itself is part of the commit message https://github.com/Krastanov/QuantumClifford.jl/commit/27a5dadc953b8b10781a88ebd720d21a23db4caf
julia> versioninfo()
Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: AMD Ryzen 7 1700 Eight-Core Processor
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, znver1)