Skip to content

Instantly share code, notes, and snippets.

@lkapelevich
Last active June 2, 2019 15:02
Show Gist options
  • Save lkapelevich/e4f539e7da084240a3c49a76554eb0bc to your computer and use it in GitHub Desktop.
Save lkapelevich/e4f539e7da084240a3c49a76554eb0bc to your computer and use it in GitHub Desktop.
using JLD
using SparseArrays
a = sprand(100, 100, 0.1)
JLD.save("a.jld", "a", a)
write(
"test.jl",
"""
using JLD
using SparseArrays
a = JLD.load($(repr(abspath("a.jld"))), "a")
c = 2a
"""
)
#############################
# In a new session
import PackageCompiler # on branch sd-notomls
open("precompile_pc.jl", "w") do io
PackageCompiler.snoop(abspath("test.jl"), io, verbose = true)
end
PackageCompiler.compile_incremental(abspath("precompile_pc.jl"), verbose = true)
# cp /home/lea/.julia/packages/PackageCompiler/UQ5UO/sysimg/sys.so ./pcimg.so
# julia --trace-compile="snoop_pc.jl" -J pcimg.so -e '@time include("test.jl")'
# 0.100931 seconds (180.74 k allocations: 10.025 MiB)
#############################
# In a new session
import SnoopCompile
SnoopCompile.@snoopc joinpath(@__DIR__(), "dummy.log") begin
using JLD, SparseArrays
include(abspath("test.jl"))
end
data = SnoopCompile.read(joinpath(@__DIR__(), "dummy.log"))
pc = SnoopCompile.format_userimg(reverse!(data[2]))
SnoopCompile.write(joinpath(@__DIR__(), "precompile_sc.jl"), pc)
using PackageCompiler
PackageCompiler.compile_incremental(abspath("precompile_sc.jl"), verbose = true)
# cp /home/lea/.julia/packages/PackageCompiler/UQ5UO/sysimg/sys.so ./scimg.so
# julia --trace-compile="snoop_sc.jl" -J ./scimg.so -e '@time include("test.jl")'
# 0.120368 seconds (178.50 k allocations: 9.842 MiB)
@lkapelevich
Copy link
Author

lkapelevich commented May 31, 2019

snoop_pc:

precompile(Tuple{typeof(Base.Printf.fix_dec), Base.TTY, Float64, String, Int64, Int64, Char, Array{UInt8, 1}})

@lkapelevich
Copy link
Author

lkapelevich commented May 31, 2019

snoop_sc:

precompile(Tuple{typeof(Base.MainInclude.include), String})
precompile(Tuple{typeof(Base.iterate), Int64, Nothing})
precompile(Tuple{typeof(JLD.h5type), JLD.JldFile, Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}, Bool})
precompile(Tuple{typeof(JLD.isopaque), Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}})
precompile(Tuple{typeof(Base.getproperty), JLD.JldDatatype, Symbol})
precompile(Tuple{typeof(JLD.read_scalar), JLD.JldDataset, HDF5.HDF5Datatype, Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}})
precompile(Tuple{Type{Base.Generator{I, F} where F where I}, getfield(JLD, Symbol("##3#4")){DataType}, Base.UnitRange{Int64}})
precompile(Tuple{typeof(Base.collect_similar), Base.UnitRange{Int64}, Base.Generator{Base.UnitRange{Int64}, getfield(JLD, Symbol("##3#4")){DataType}}})
precompile(Tuple{typeof(Base.getindex), Array{UInt64, 1}, Int64})
precompile(Tuple{typeof(Base.Printf.fix_dec), Base.TTY, Float64, String, Int64, Int64, Char, Array{UInt8, 1}})
precompile(Tuple{getfield(Blosc, Symbol("##1#2"))})

@lkapelevich
Copy link
Author

lkapelevich commented Jun 2, 2019

precompile(Tuple{getfield(JLD, Symbol("##s27#8")), Int, Int, Int, Int, Int}) commented out in precompile_sc.jl.

Rebuilding Julia with precompile_sc.jl in base/userimg.jl and running --trace-compile="check_scimg.jl" -e 'include("test.jl")' gives:

check_scimg.jl:

precompile(Tuple{typeof(Base.iterate), Int64, Nothing})
precompile(Tuple{typeof(JLD.h5type), JLD.JldFile, Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}, Bool})
precompile(Tuple{typeof(JLD.isopaque), Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}})
precompile(Tuple{typeof(Base.getproperty), JLD.JldDatatype, Symbol})
precompile(Tuple{typeof(JLD.read_scalar), JLD.JldDataset, HDF5.HDF5Datatype, Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}})
precompile(Tuple{Type{Base.Generator{I, F} where F where I}, getfield(JLD, Symbol("##3#4")){DataType}, Base.UnitRange{Int64}})
precompile(Tuple{typeof(Base.collect_similar), Base.UnitRange{Int64}, Base.Generator{Base.UnitRange{Int64}, getfield(JLD, Symbol("##3#4")){DataType}}})
precompile(Tuple{typeof(Base.getindex), Array{UInt64, 1}, Int64})

@lkapelevich
Copy link
Author

lkapelevich commented Jun 2, 2019

Rebuilding Julia with precompile_sc.jl in base/userimg.jl and using SnoopCompile to trace compiles gives:

precompile(Tuple{typeof(JLD.jlconvert), Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}, JLD.JldFile, Ptr{UInt8}})
precompile(Tuple{typeof(JLD.read_scalar), JLD.JldDataset, HDF5.HDF5Datatype, Type{Int}})

@lkapelevich
Copy link
Author

lkapelevich commented Jun 2, 2019

Rebuilding Julia with precompile_pc.jl in base/userimg.jl and using --trace-compile to trace compiles gives no output.

Rebuilding Julia with precompile_pc.jl in base/userimg.jl and using SnoopCompile to trace compiles gives:

precompile(Tuple{typeof(Base.ht_keyindex2!), Base.Dict{Any, Any}, Type{Int}})
precompile(Tuple{typeof(Base.ht_keyindex), Base.Dict{Type, JLD.JldDatatype}, Type{Int}})
precompile(Tuple{typeof(Base.convert), Type{Array{Int64, 1}}, Array{Int64, 1}})
precompile(Tuple{typeof(Base.convert), Type{Array{Float64, 1}}, Array{Float64, 1}})
precompile(Tuple{typeof(Base.all), typeof(identity), Array{Any, 1}})
precompile(Tuple{typeof(Base.map), typeof(identity), Base.UnitRange{Int64}})
precompile(Tuple{getfield(Base, Symbol("##all#574")), typeof(identity), typeof(Base.all), typeof(identity), Array{Any, 1}})
precompile(Tuple{typeof(JLD.jlconvert), Type{SparseArrays.SparseMatrixCSC{Float64, Int64}}, JLD.JldFile, Ptr{UInt8}})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment