-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Closed
Copy link
Description
This was found on discourse with the goal being C interop:
julia> struct Foo
id:: UInt64
tag::NTuple{32, UInt8}
start_comment::NTuple{4096, UInt8}
end_comment::NTuple{4096, UInt8}
end
julia> string2ntuple(s::String, len) = ntuple(i -> i <= ncodeunits(s) ? codeunit(s, i) : 0x0, len)
string2ntuple (generic function with 1 method)
julia> dataset = [Foo(
0,
string2ntuple("test_tag", 32),
string2ntuple("start_comment", 4096),
string2ntuple("end_comment", 4096),
)]
# seems to hang, is stuck in compilation somewhere
# the same happens for `Foo[Foo(...)]`Some variations on the above that are otherwise functionally equivalent DO NOT show this behavior:
Fast variations
julia> @time dataset = Vector{Foo}(undef, 1);
0.000011 seconds (1 allocation: 8.188 KiB)
julia> @time dataset[1] = Foo(
0,
string2ntuple("test_tag", 32),
string2ntuple("start_comment", 4096),
string2ntuple("end_comment", 4096),
); # silence output
0.022675 seconds (4.25 k allocations: 344.307 KiB, 98.39% compilation time)
julia> @time dataset[1] = Foo(
0,
string2ntuple("test_tag", 32),
string2ntuple("start_comment", 4096),
string2ntuple("end_comment", 4096),
); # silence output
0.000272 seconds (9 allocations: 89.016 KiB)
julia> @time data2 = Foo[];
0.000010 seconds (1 allocation: 64 bytes)
julia> @time push!(data2, Foo(
0,
string2ntuple("test_tag", 32),
string2ntuple("start_comment", 4096),
string2ntuple("end_comment", 4096),
)); # silence output
0.014009 seconds (9.06 k allocations: 700.702 KiB, 97.74% compilation time)The last push! version is also mostly compilation, but I don't know if that's fast or slow relative to regular structs.
show itself is also extremely slow to compile, but does eventually finish:
julia> @time show(stdout, dataset) # that's the dataset from above
Foo[Foo(0x0000000000000000, [...] # I've ommited all the empty data
)] 32.848714 seconds (588.41 k allocations: 60.553 MiB, 0.04% gc time, 99.28% compilation time)Metadata
Metadata
Assignees
Labels
No labels