-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature request: skip methods for precompilation? #12
Comments
Hi Hongyang,
Could you provide a MWE? If
Preferably, I would like to fix those problems instead of asking users to fine-tune such problems. In theory, |
I tried to come up with a MWE, but I couldn't reproduce the error without using the method in my package. And what makes it even more strange is that for small data files I don't see allocations; it only happens for large data sizes. Here is how I reproduce the issue:
# Extra allocation triggered by PrecompileSignatures
precompile(fillmesh, (MetaVLSV, String))
precompile(fillmesh, (MetaVLSV, Vector{String}))
using Vlasiator
file = "bulk.0000003.vlsv"
meta = load(file)
@time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false); On my Linux laptop, # Master
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.389661 seconds (468.68 k allocations: 45.322 MiB, 1.75% gc time, 85.16% compilation time)
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.078479 seconds (496 allocations: 20.267 MiB, 12.25% gc time) # Master + two extra precompilations of fillmesh
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.689447 seconds (3.64 M allocations: 137.799 MiB, 2.88% gc time, 87.91% compilation time)
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.100166 seconds (2.30 M allocations: 67.053 MiB, 15.35% gc time) Note that on current master I removed using PrecompileSignatures: @precompile_signatures
@precompile_signatures(Vlasiator) I know that extra allocations are solely from this line. I agree that this seems to be a Julia bug that is unveiled by |
Thanks for the extensive information! Before I go in and download the files and set everything up, could you double check that the problem persists if you benchmark with
|
and which Julia version are you running? |
I am running on Julia v1.7.3. Results with # Master 1st time
1.288102 seconds (3.02 M allocations: 179.112 MiB, 4.44% gc time, 93.05% compilation time)
# Master 2nd time
0.107818 seconds (609 allocations: 20.273 MiB, 19.43% gc time)
# Master + 2lines 1st time
1.105118 seconds (3.66 M allocations: 138.418 MiB, 2.61% gc time, 90.55% compilation time)
# Master + 2lines 2nd time
0.117375 seconds (2.30 M allocations: 67.058 MiB, 18.13% gc time) |
Hmm there is definitely something interesting going on there. Thanks for letting me know. Unfortunately, I will likely not investigate this further. The first times are as expected namely a large decrease in allocations and a small decrease in running time. The running time should become much lower once Julia caches binaries too (JuliaLang/julia#44527). Till that time, what you can do is to add a real-time workload to your package too as is described in https://timholy.github.io/SnoopCompile.jl/stable/snoopi_deep_parcel/. See also the Makie example in the README of this repository. The workload can trigger compilation on methods that |
Thanks for the tips! My gut feeling is that somehow However, for now it may be still useful to skip certain methods in |
Yes SnoopCompile is useful and generic profiling can also help a lot with Also try Julia 1.8. It's very likely that the problem is solved there. The compiler team is really doing great stuff at the language-side. |
Indeed! I just tried Julia v1.8.0-rc1: # master + 2lines for precompilation
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.440889 seconds (932.38 k allocations: 68.000 MiB, 8.31% gc time, 89.19% compilation time)
julia> @time data, vtkGhostType = Vlasiator.fillmesh(meta, ["proton/vg_blocks"]; verbose=true, skipghosttype=false);
[ Info: scanning AMR level 0...
[ Info: reading variable proton/vg_blocks...
[ Info: scanning AMR level 1...
[ Info: reading variable proton/vg_blocks...
0.048697 seconds (457 allocations: 20.265 MiB) Can't wait for the official release of Julia v1.8! One more question: what is the difference between the |
So, let's close the issue? :) I don't think that adding a filter is the right way forward. It shouldn't be necessary.
I fully agree!
Calling |
Hi,
I have been looking at a very strange allocation in
searchsorted
orinsorted
used in my packageVlasiator.jl
. I notice that this somehow relates to the usage ofPrecompileSignatures.jl
: if I manually precompile the methods detected byPrecompileSignatures.jl
instead of relying on@precompile_signatures(Vlasiator)
, the strange allocation of tiny vectors is gone.I checked methods detected for precompilation from
PrecompileSignatures.precompilables(Vlasiator)
: when I skip the ones that looks likeIt may be hard for me to fully understand the situation, but my feeling is that
PrecompileSignatures.jl
is aggressively searching for methods that can be precompiled that occasionally leads to unexpected behaviors. Is it possible to skip certain methods for precompilation? For example, I don't know why__init__
needs to be precompiled.For now I may simply explicitly list all the methods that I think are valid suggested by
precompilables
. If you have any insights into this issue, please let me know!The text was updated successfully, but these errors were encountered: