Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upMeasure the heap memory usage of the remaining derived types of Element #6951
Comments
|
You can see the effects of your changes by running |
|
I am keen, but I'll also leave a comment :) |
|
@jdm So, basically, I should fill util/mem.rs with types, right? (Or should I impl them in their respective files?) |
|
For a type T that does not currently implement HeapSizeOf, there are thee solutions:
|
|
@jdm Do I ignore Root and JS? |
|
|
|
@jdm What about Trusted? |
|
Interesting question. Just add an ignore attribute for now. |
|
@jdm Just wanted to let you know that I only have 75 errors left, so you can expect a PR soon :3 |
|
Ok, I am almost done, I just have 2 more, which are very weird:
and |
|
Yes, the first one is #6870. For the second, we probably don't have an implementation for &T where T: HeapSizeOf. |
|
That being said, why is |
|
@jdm Oh, ok. TBH I have no idea, I just wrote a script to add this to every struct and enum in script/dom, then ignore the types that need to be ignored, and then I manually fixed all errors. I'll write it for &T then, and maybe try to fix #6870. I also have a question, why did you say one needs a variant for every type derived of Node, couldn't it just be a Element(_) and then ElementCast or am I missing something? |
|
We should not add an impl for &T. We should remove the annotation instead. |
|
As for why we're doing this, the problem is that if we use ElementCast::to_ref and then call heap_size_of on it, all we're doing is calling Element::heap_size_of_children (ie. measuring the members of the Element struct). If we actually have an HTMLIFrameElement, we don't measure of its members because we don't call HTMLIFrameElement::heap_size_of_children. |
|
@jdm Oh, ok. Could you elaborate on what you said first, what do you mean by "remove the annotation"? And am I doing this right, I mean, IMHO, it won't hurt if we add HeapSizeOf to as much as we can, no? |
|
So on one hand, it won't hurt in the common case . On the other hand, in this case an implementation for |
|
Surely we shouldn't count borrowed references? |
|
Oh, maybe you misunderstood. I mean if I am doing everything right, by appending HeapSizeOf to as much as possible ie not about the Option<&Node> |
|
I think the only downside is the existence of generated code that is never called, which will increase compile times just by existing. That being said, it's not clear to me how much of a burden that will be. |
Measure heap memory usage for more types. Fixes #6951 Also adds HeapSizeOf implementations/derive for some types. I've used "Cannot calculate Heap size" as a reason everywhere, because my imagination is rather limited. If you'd like me to change this message for specific types, please write something like this: "Trusted - Cannot calculate Heap size for Trusted" so that it would be easier for me to replace them through a script :) <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7097) <!-- Reviewable:end -->
#6874 added the basics for measuring the heap memory used by the DOM tree. However, the
heap_size_of_eventtargetmethod inmem.rsis incomplete - it needs a variant for every single derived type ofNode(Element, HTMLElement, HTMLTextAreaElement, etc.) What this means in practice is adding#[derive(HeapSizeOf)]to the type that needs measuring, adding a new match arm toheap_size_of_eventtarget, and adding an#[ignore_heap_size_of = "reason"]annotation to any fields that can't easily be measured (ie. types that are not defined in one of Servo's crates).There's no particular reason why one person would need to do all of the types here, since there's a lot of them, but maybe somebody's keen. Otherwise, please leave a comment here listing the types you're intending to implement heap measurement for.