-
-
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
use a non-stack-based algorithm to compute summarysize #20161
Conversation
|
||
Compute the amount of memory used by all unique objects reachable from the argument. | ||
Keyword argument `exclude` specifies the types of objects to exclude from the traversal. | ||
Keyword argument `chargeall` specifies the types of objects to always charge the size of all of their fields, even if those fields would normally be excluded. |
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.
Might be nice to provide keyword arguments as a bulleted list. Makes it a little easier to read. It would also be good to add line breaks to maintain the line length guidelines.
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.
Cf. reference example in the manual (bullet 4).
Keyword argument `exclude` specifies the types of objects to exclude from the traversal. | ||
Keyword argument `chargeall` specifies the types of objects to always charge the size of all of their fields, even if those fields would normally be excluded. | ||
""" | ||
function summarysize(obj::ANY; exclude::ANY = Union{DataType, TypeName}, chargeall::ANY = Union{TypeMapEntry, Method, Core.MethodInstance}) |
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.
Same comment regarding line lengths. You could just align exclude
and chargeall
beneath obj
; that style is used elsewhere.
Is there a way to test that #19707 is fixed so that we can track it going forward? |
end | ||
if isa(obj, UnionAll) | ||
# black-list of items that don't have a Core.sizeof | ||
return 2 * sizeof(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.
the old computation for UnionAll also added summarysize(obj.body, seen, excl) + summarysize(obj.var, seen, excl)
, is this new version undercounting?
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.
the fields are handle elsewhere now. (unrelated, but the old version was also over-counting the Core.sizeof
)
val = getfield(x, i) | ||
end | ||
end | ||
if nfields(x) > i |
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.
Should this be nf > i
?
in addition to not using stack space, this doesn't need as many special cases
a62e179
to
8cd9d22
Compare
nothing too fancy here, just swapping the existing stack-based DFS algorithm for a heap-based one. this'll prevent this method from ever causing stack overflow, which will fix #19707.