-
-
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
Extend "whos" to print the size (in bytes) of Julia objects #11461
Conversation
|
||
sz = 0 | ||
try | ||
sz = sizeof(x) |
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.
Out of curiosity, which types of objects does this fail on?
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.
It fails on the Symbol type. An Error is raised that says "value does not have a canonical binary representation."
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.
Defaulting to 0 in such cases is also a bit odd, but OTOH since symbols are reused perhaps that's as good as any other choice.
But if Symbols are the main way in which this fails, it might be better to say
if !isa(x, Symbol)
try
sz = sizeof(x)
...
because exceptions are a slow way of doing control flow. (More relevant for programmatic usage of totalsize
than for usages of whos()
, of course.) For reference, the builtin definition of sizeof
might be helpful.
It would be great to add some tests of the |
@timholy, what do you think about the |
I think it's a good addition. Thanks for doing it. |
I think that I addressed everything that @timholy pointed out. The CI failures seem unrelated to my change. |
This function is equivalent to the "eachindex" function that is already defined for the AbstractArray type. This allows code that can generically iterate over Tuple indices in addition to AbstractArray indices.
This function measures the total number of bytes used by Julia objects. Fixes #7603 I don't think that this function should get exported, so it doesn't make sense to me that it should be documented in the manual.
Fixes #3393: whos() should print the memory usage of the objects As of this change, "whos" prints the total size of an object in bytes. A new column was added to the output. julia> whos() Base 16 bytes Module Compat 16 bytes Module Core 16 bytes Module Main 16 bytes Module WAV 16 bytes Module ans 8 bytes Int64 wav1 33066 KB Tuple{Array{Int16,2},UInt32,UInt16,Dict{Symbol,Any}} wav2 129 MB Tuple{Array{Float64,2},UInt32,UInt16,Dict{Symbol,Any}} It isn't expected, but totalsizeof might throw an exception. Prepare whos so that the user interaction doesn't break.
appveyor failure was #11890 |
👍 |
Bump - can we merge this? |
I think this needs a bit of work before getting merged (or some follow up work if we merge this). Instead of using a I am hesitant to merge this as the result will often be wrong if users do not carefully implement the |
I wonder if a different approach might be to allow a GC pass to attribute all allocated bytes to some gc root object. You could even generalize that to take a set of arbitrary "roots" and follow them, attributing data to them as it goes. It's unclear what to do when accounting for multiply reachable memory. |
This pull request changes the
whos
function to print out the size of Julia objects (#3393). I added atotalsizeof
function to measure the size of Julia objects (#7603). Finally, it adds aneachindex
for Tuple types so thattotalsizeof
can treat Tuples like other iterable objects.