-
Notifications
You must be signed in to change notification settings - Fork 9
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
SumType becomes less memory efficient with non-isbits fields #65
Comments
ok actually changing (anyway, what all of that expands to which could be relevant to this (in the first case here) is just SumTypes.@sum_type A{X, Y} begin
B{X}(ht::var"##B#225"{X})
C(ht::var"##C#227")
D{Y}(ht::var"##D#228"{Y})
end
where the inner types are mutable/immutable structs with all fields defined as above.) |
So one thing to notice is that your
which brings it down to And with the non-isbits definition that stored a string, I get
so that's also good. Regarding the increase in footprint from the non-isbits |
thank you a lot (I always forget to add parameters :( ) so the last case where memory increase is just when the vector is abstractly typed, right? Then I think this is not really that problematic, so I think this issue can be closed if you agree, or anyway I will change the title to reflect reality |
mmh I tried it now, I think that you mean the one which stores an Int right? Then I think I misunderstood you in my last comment above Yes, with a julia> vec_a = A{Int, String}[rand((B,C,D))() for _ in 1:10^5];
julia> Base.summarysize(vec_a)
6561005
julia> Base.summarysize(vec_a)
6204757
julia> Base.summarysize(vec_a)
6039637
julia> Base.summarysize(vec_a)
5999493
julia> Base.summarysize(vec_a)
6170045
julia> Base.summarysize(vec_a)
6450517 |
Yikes, that is weird, I have no idea what could cause that.
No I meant the |
okay, but I think then that the memory usage is more on 6 million bytes than on the 4.3 million in this case, not totally sure about the amount because Base.summarysize is not totally sure either :D (in general it is never sure on sum types, and sometimes it goes almost 2x on some runs in respect to others in some cases I tested) Do you think this is worth an issue in the Julia repo? |
Opened an issue about Base.summarysize: JuliaLang/julia#53061, seems like it happens also in simpler structs |
just an update because the issue was fixed on Julia nightly, on it: # first version in the main comment
julia> vec_a = A[rand((B,C,D))() for _ in 1:10^5];
julia> Base.summarysize(vec_a)
4526700
julia> vec_a = A{Int, Int}[rand((B,C,D))() for _ in 1:10^5];
julia> Base.summarysize(vec_a)
3739036
# second version in the main comment
julia> vec_a = A[rand((B,C,D))() for _ in 1:10^5];
julia> Base.summarysize(vec_a)
5866653
julia> vec_a = A{Int, String}[rand((B,C,D))() for _ in 1:10^5];
julia> Base.summarysize(vec_a)
5066685 it seems better now with the right numbers |
Actually now that I investigated it a bit more, in Julia 1.11 where the issue with Base.summarysize has been fixed, I actually see very often that sum types outperform |
I noticed this when developing https://github.com/JuliaDynamics/MixedStructTypes.jl e.g.
now
let's use instead
now
Is there a way to improve this? Or is this expected? Notice that in the second case the memory occupied is very similar to just a compactification of all fields in a unique struct
The text was updated successfully, but these errors were encountered: