-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Base.summarysize returns different memory usage values on different runs #53061
Comments
The trouble comes from doing the wrong query here: Line 60 in c42df60
Versus a more correct implementation of the function, as seen here that uses julia/base/compiler/utilities.jl Line 95 in c42df60
|
Hey @vtjnash, I would like to work on this issue it would be great if you can guide me. Thanks. |
It looks like this has been a problem since 1.0, so it may need to be reverse ported.
|
I don't think that could be the same, since the Union-storage optimization (that is currently resulting in unreliable over-estimation, wasn't implemented until later) @re1san If you take a look at the difference between those two implementations, do you see what parts of the base/compiler/utilities.jl there could be ported to the base/summarysize.jl so that the estimate by summarysize is the same as the accurate value computed by the compiler code? |
By the way this can even invert the memory efficiency of structs and mutable structs: struct Z end
struct A
b::Union{Z, Tuple{Float64, Float64}}
d::Union{Z, Int}
c::Union{Z, Symbol}
end
mutable struct B
b::Union{Z, Tuple{Float64, Float64}}
d::Union{Z, Int}
c::Union{Z, Symbol}
end
vec_notmut = A[A(Z(), 1, :s) for _ in 1:10^6];
vec_mut = B[B(Z(), 1, :s) for _ in 1:10^6]; which results in julia> Base.summarysize(vec_notmut)
83717104
julia> Base.summarysize(vec_mut)
56000064 (if it is the same problem, I'm a bit of unsure because here summarysize for |
Somewhat unclear, but it is at least true that Array/Memory does use a different branch condition when deciding whether to double-count the memory usage of the elements: Line 143 in c42df60
|
So, would nf = nfields(x)
- ft = typeof(x).types
- if !isbitstype(ft[i]) && isdefined(x, i)
- val = getfield(x, i)
+ dt = typeof(x)
+ dtfd = Base.DataTypeFieldDesc(dt)
+ if isdefined(x, i)
+ f = getfield(x, i)
+ if dtfd[i].isptr || !Base.datatype_pointerfree(typeof(f))
+ val = f
+ end
end
end take care of #53061 (comment)? julia> Base.summarysize(ex)
5600056
julia> Base.summarysize(ex)
5600056
julia> Base.summarysize(ex)
5600056 The second case ( |
I checked it out your implementation @xlxs4, I think I understood the logic and it seems fine to me |
Could you open up a PR with that @xlxs4? |
fixes #53061 Co-authored-by: Orestis Ousoultzoglou <orousoultzoglou@gmail.com>
fixes #53061 Co-authored-by: Orestis Ousoultzoglou <orousoultzoglou@gmail.com>
fixes #53061 Co-authored-by: Orestis Ousoultzoglou <orousoultzoglou@gmail.com>
fixes #53061 Co-authored-by: Orestis Ousoultzoglou <orousoultzoglou@gmail.com>
fixes #53061 Co-authored-by: Orestis Ousoultzoglou <orousoultzoglou@gmail.com>
MWE:
now if you execute:
This can become very extreme in some situation, I saw a 2x difference between runs on a more complex vector of structs.
Tested in 1.10 and nightly, same behaviour
The text was updated successfully, but these errors were encountered: