-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Base: Add count
argument to Base.summarysize
#58874
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: master
Are you sure you want to change the base?
Conversation
size::Int = (ss.count ? 1 : (7 * Core.sizeof(Int) + 6 * Core.sizeof(Int32))) | ||
size += (ss.count ? 1 : (4 * nfields(obj) + ifelse(Sys.WORD_SIZE == 64, 4, 0))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know where these magic numbers were pulled from, so I'm not sure if this is 1 object or 2 (or 3?)
I'll need to reverse engineer before merging.
It would be good to specify in the docstring whether count returns the number of heap allocations or the number of Julia objects. Does a 1000-element Memory of integers count as one or 1000? |
0a37de0
to
345a791
Compare
Frequently the number of allocations can be more important for performance than the amount of memory allocated. This adds a small utility to `summarysize` to allow counting the number of unique reachable objects, which can be useful to understand, e.g., if you are performing many small allocations or how many of the allocations in a function ended up reachable from the result.
345a791
to
f254a9d
Compare
end | ||
|
||
nth_pointer_isdefined(obj, i::Int) = ccall(:jl_nth_pointer_isdefined, Cint, (Any, Csize_t), obj, i-1) != 0 | ||
get_nth_pointer(obj, i::Int) = ccall(:jl_get_nth_pointer, Any, (Any, Csize_t), obj, i-1) | ||
|
||
""" | ||
Base.summarysize(obj; exclude=Union{...}, chargeall=Union{...})::Int | ||
Base.summarysize(obj; count = false, exclude=Union{...}, chargeall=Union{...})::Int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be clearer as:
Base.summarysize(obj; count = false, exclude=Union{...}, chargeall=Union{...})::Int | |
Base.summarysize(obj; count::Symbol = :size, exclude=Union{...}, chargeall=Union{...})::Int |
so the new functionality would be summarysize(x; count=:allocations)
In many cases, number of allocations is more important than memory allocated (w.r.t. performance).
This adds a small utility to
summarysize
to allow counting the number of unique reachable objects, which can be useful to understand, e.g., if you are performing many small allocations or how many of the allocations in a function ended up reachable from the result.