Skip to content
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

Merged
merged 1 commit into from
Jan 23, 2017

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Jan 20, 2017

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.


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.
Copy link
Member

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.

Copy link
Member

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})
Copy link
Member

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.

@ararslan
Copy link
Member

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)
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Member

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
@vtjnash vtjnash force-pushed the jn/summarysize-no-stack branch from a62e179 to 8cd9d22 Compare January 21, 2017 18:10
@vtjnash vtjnash merged commit 5398799 into master Jan 23, 2017
@vtjnash vtjnash deleted the jn/summarysize-no-stack branch January 23, 2017 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StackOverflowError in summarysize during misc test
5 participants