Hello!
I wrote a bunch of libs in Julia that all work together. One lib in particular exists just to read and stream a certain data from HDF5 files. One of the functions in this lib has the job of, given one of these HDF5 files, read the contents of its summary and display it. Note, it doesn’t compute the summary from the data, that has already been done and stored inside the HDF5 alongside the data. This function reads only the summary and displays it on the screen. It’s just a few lines long.
Now, the thing I just described, after I restart Julia, and after all the import
s have run, takes 15 seconds to run the first time. This is a crazy amount of time. My guess is that this time is spent compiling something, so I thought I would look into PrecompileTools
so that this is done just once and doesn’t have to happen every time I restart Julia. Schematically I have:
import ...
(...)
@time printstats(filename)
The last line prints
2.680033 seconds (847.55 k allocations: 44.609 MiB, 99.26% compilation time);
First off, this isn’t accurate. I timed it on my wristwatch and that line takes 15 seconds the first time around. No idea why @time
says 2.7 secs.
Second time around it prints
0.016743 seconds (162.97 k allocations: 6.526 MiB)
Alright, this is what I would expect.
So I tried using PrecompileTools
. I add it to the package’s env, I add using PrecompileTools
and then I write:
@setup_workload begin
@compile_workload begin
printstats(filename)
end
end
I restart Julia, do my imports, and the run the timed line, which now prints
0.105645 seconds (168.01 k allocations: 6.763 MiB, 82.82% compilation time)
Again not accurate, my wristwatch shows 9 and half seconds.
Let me emphasize what a microscopic amount of work reading and printing this data is. None of these times can be explained by the work that actually matters to me.
What’s going on here? Why are the @time
s wrong? Why does it seem that PrecompileTools has very little effect on the times? What can I do to avoid these constant recompilations?
Thank you