First off, thanks for you response with those tools! the --trace-compile
option is pretty hard for me to decipher, so I’m including some results below.
I also used Base.summarysize
on both the struct with just Int
s, and the one with UInt
s.
size of Int
struct = size of UInt
struct = 120 bytes. Sooo, I failed at making the struct smaller.
Note that for the outputs below, I stopped used the extractrightUInt
function and am just using extractright
in its place. The only difference between the code across these versions is the internal types of the DevDataID
struct, as shown in my initial post.
I also left the timing results in to make the difference clear. I know that leaving this in adds some of the precompile lines before the result gets printed.
Int
version:
julia --trace-compile=stderr decoder2.jl
precompile(Tuple{Type{UInt64}, UInt64})
precompile(Tuple{typeof(Base.:(!=)), UInt64, UInt64})
precompile(Tuple{Parameters.var"#@with_kw", LineNumberNode, Module, Any})
precompile(Tuple{typeof(Core.Compiler.convert), Type{DataType}, Type{Tuple{Any, Int64}}})
precompile(Tuple{typeof(Parameters.with_kw), Expr, Module, Bool})
precompile(Tuple{typeof(Base.:(==)), Tuple{Expr, Int64}, Int64})
precompile(Tuple{typeof(Base.iterate), Base.Iterators.Enumerate{Parameters.Lines}, Tuple{Int64, Int64}})
precompile(Tuple{typeof(Base.setindex!), OrderedCollections.OrderedDict{Any, Any}, String, Symbol})
precompile(Tuple{typeof(OrderedCollections.hashindex), Symbol, Int64})
precompile(Tuple{typeof(Base.setproperty!), OrderedCollections.OrderedDict{Any, Any}, Symbol, Int64})
precompile(Tuple{typeof(Base.setindex!), OrderedCollections.OrderedDict{Any, Any}, Int64, Symbol})
precompile(Tuple{typeof(Base.isequal), Symbol, Symbol})
precompile(Tuple{typeof(Base.prepend!), Array{Any, 1}, Array{Any, 1}})
precompile(Tuple{typeof(Base.:(!=)), Array{Any, 1}, Array{Any, 1}})
precompile(Tuple{Core.var"#@__doc__", LineNumberNode, Module, Any})
precompile(Tuple{Type{Main.DevDataID}})
precompile(Tuple{typeof(Base.getindex), Type{Main.DevDataID}})
precompile(Tuple{typeof(Main.txttostruct), String, String, Main.DevDataID, Array{Main.DevDataID, 1}})
precompile(Tuple{Type{Main.DevDataID}, String, String, Int64, Int64, Int64})
precompile(Tuple{typeof(Base.push!), Array{Main.DevDataID, 1}, Main.DevDataID})
precompile(Tuple{typeof(Base.prettyprint_getunits), Int64, Int64, Int64})
precompile(Tuple{Type{Float64}, Float64})
precompile(Tuple{typeof(Base.Ryu.writefixed), Float64, Int64})
0.012884 seconds (2.32 k allocations: 129.162 KiB, 99.67% compilation time)
precompile(Tuple{Type{Int64}, Float64})
precompile(Tuple{typeof(Base.:(==)), Float64, Int64})
precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, Int64, String, Vararg{String}})
0.000010 seconds (9 allocations: 720 bytes)
UInt
version:
julia --trace-compile=stderr decoder2.jl
precompile(Tuple{Type{UInt64}, UInt64})
precompile(Tuple{typeof(Base.:(!=)), UInt64, UInt64})
precompile(Tuple{Parameters.var"#@with_kw", LineNumberNode, Module, Any})
precompile(Tuple{typeof(Core.Compiler.convert), Type{DataType}, Type{Tuple{Any, Int64}}})
precompile(Tuple{typeof(Parameters.with_kw), Expr, Module, Bool})
precompile(Tuple{typeof(Base.:(==)), Tuple{Expr, Int64}, Int64})
precompile(Tuple{typeof(Base.iterate), Base.Iterators.Enumerate{Parameters.Lines}, Tuple{Int64, Int64}})
precompile(Tuple{typeof(Base.setindex!), OrderedCollections.OrderedDict{Any, Any}, String, Symbol})
precompile(Tuple{typeof(OrderedCollections.hashindex), Symbol, Int64})
precompile(Tuple{typeof(Base.setproperty!), OrderedCollections.OrderedDict{Any, Any}, Symbol, Int64})
precompile(Tuple{typeof(Base.setindex!), OrderedCollections.OrderedDict{Any, Any}, Int64, Symbol})
precompile(Tuple{typeof(Base.isequal), Symbol, Symbol})
precompile(Tuple{typeof(Base.prepend!), Array{Any, 1}, Array{Any, 1}})
precompile(Tuple{typeof(Base.:(!=)), Array{Any, 1}, Array{Any, 1}})
precompile(Tuple{Core.var"#@__doc__", LineNumberNode, Module, Any})
precompile(Tuple{Type{Main.DevDataID}})
precompile(Tuple{typeof(Base.getindex), Type{Main.DevDataID}})
precompile(Tuple{typeof(Main.txttostruct), String, String, Main.DevDataID, Array{Main.DevDataID, 1}})
precompile(Tuple{Type{Main.DevDataID}, String, String, UInt8, UInt64, UInt16})
precompile(Tuple{typeof(Base.push!), Array{Main.DevDataID, 1}, Main.DevDataID})
precompile(Tuple{typeof(Base.prettyprint_getunits), Int64, Int64, Int64})
precompile(Tuple{Type{Float64}, Float64})
precompile(Tuple{typeof(Base.Ryu.writefixed), Float64, Int64})
0.011373 seconds (4.11 k allocations: 234.971 KiB, 99.46% compilation time)
precompile(Tuple{Type{Int64}, Float64})
precompile(Tuple{typeof(Base.:(==)), Float64, Int64})
precompile(Tuple{typeof(Base.print), Base.GenericIOBuffer{Array{UInt8, 1}}, Int64, String, Vararg{String}})
0.000013 seconds (8 allocations: 704 bytes)
My original question (mostly) remains, why does the UInt
version take so many more allocations up front, even if it is the same size according to Base.summarysize
?
My secondary question now is why does copying a struct take ~6x the size of the struct in memory?