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

Measure Arc<Locked<T>> fields properly. #18455

Merged
merged 1 commit into from Sep 12, 2017

Conversation

nnethercote
Copy link
Contributor

@nnethercote nnethercote commented Sep 12, 2017

Currently when we measure various Arc<Locked> fields we don't measure the T
itself, but only the descendants of the T. This patch fixes this.

This fix requires introducing a new trait, MallocUnconditionalShallowSizeOf,
which is implemented for servo_arc::Arc. A similar trait,
MallocConditionalShallowSizeOf, is also introduced, though it has no uses as
yet.


  • ./mach build -d does not report any errors
  • ./mach test-tidy does not report any errors
  • These changes fix #__ (github issue number if applicable).
  • There are tests for these changes OR
  • These changes do not require tests because they are tested in Gecko.

This change is Reviewable

Currently when we measure various Arc<Locked<T>> fields we don't measure the T
itself, but only the descendants of the T. This patch fixes this.

This fix requires introducing a new trait, MallocUnconditionalShallowSizeOf,
which is implemented for servo_arc::Arc. A similar trait,
MallocConditionalShallowSizeOf, is also introduced, though it has no uses as
yet.
@highfive
Copy link

Heads up! This PR modifies the following files:

  • @bholley: components/style/stylesheets/media_rule.rs, components/style/stylesheets/style_rule.rs, components/style/stylesheets/supports_rule.rs, components/style/stylesheets/page_rule.rs, components/style/stylesheets/stylesheet.rs and 2 more
  • @canaltinova: components/style/stylesheets/media_rule.rs, components/style/stylesheets/style_rule.rs, components/style/stylesheets/supports_rule.rs, components/style/stylesheets/page_rule.rs, components/style/stylesheets/stylesheet.rs and 2 more
  • @emilio: components/style/stylesheets/media_rule.rs, components/style/stylesheets/style_rule.rs, components/style/stylesheets/supports_rule.rs, components/style/stylesheets/page_rule.rs, components/style/stylesheets/stylesheet.rs and 2 more

@highfive
Copy link

warning Warning warning

  • These commits modify style code, but no tests are modified. Please consider adding a test!

@highfive highfive added the S-awaiting-review There is new code that needs to be reviewed. label Sep 12, 2017
@nnethercote
Copy link
Contributor Author

@nnethercote
Copy link
Contributor Author

r? @jdm

@highfive highfive assigned jdm and unassigned wafflespeanut Sep 12, 2017
@jdm
Copy link
Member

jdm commented Sep 12, 2017

@bors-servo: r+

@bors-servo
Copy link
Contributor

📌 Commit 779fbda has been approved by jdm

@highfive highfive added S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. and removed S-awaiting-review There is new code that needs to be reviewed. labels Sep 12, 2017
@bors-servo
Copy link
Contributor

⌛ Testing commit 779fbda with merge bffe158...

bors-servo pushed a commit that referenced this pull request Sep 12, 2017
Measure Arc<Locked<T>> fields properly.

Currently when we measure various Arc<Locked<T>> fields we don't measure the T
itself, but only the descendants of the T. This patch fixes this.

This fix requires introducing a new trait, MallocUnconditionalShallowSizeOf,
which is implemented for servo_arc::Arc. A similar trait,
MallocConditionalShallowSizeOf, is also introduced, though it has no uses as
yet.

<!-- Please describe your changes on the following line: -->

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [ ] There are tests for these changes OR
- [X] These changes do not require tests because they are tested in Gecko.

<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18455)
<!-- Reviewable:end -->
@bors-servo
Copy link
Contributor

☀️ Test successful - android, arm32, arm64, linux-dev, linux-rel-css, linux-rel-wpt, mac-dev-unit, mac-rel-css1, mac-rel-css2, mac-rel-wpt1, mac-rel-wpt2, mac-rel-wpt3, mac-rel-wpt4, windows-msvc-dev
Approved by: jdm
Pushing bffe158 to master...

@bors-servo bors-servo merged commit 779fbda into servo:master Sep 12, 2017
@highfive highfive removed the S-awaiting-merge The PR is in the process of compiling and running tests on the automated CI. label Sep 12, 2017
@bzbarsky
Copy link
Contributor

So I'd been hoping we would do something where you could call foo.size_of() (possibly passing a guard) on an Arc<Locked<T>> and it would automatically do the right thing for you, instead of having to make two separate function calls to measure the size of the Locked<T> and the things hanging off the T. Seems like it would be a lot less error-prone....

@nnethercote nnethercote deleted the measure-Arc-Locked-properly branch September 12, 2017 22:16
@nnethercote
Copy link
Contributor Author

So I'd been hoping we would do something where you could call foo.size_of() (possibly passing a guard) on an Arc<Locked> and it would automatically do the right thing for you

I tried that and it didn't work all that well. I created a new trait called MallocSizeOfWithGuard, because you have to pass in the guard so the normal MallocSizeOf trait doesn't work. But then, sometimes to measure the T you need to invoke MallocSizeOfWithGuard:

self.rules.unconditional_shallow_size_of(ops) + self.rules.read_with(guard).size_of(guard, ops)

but sometimes you need to invoke MallocSizeOf:

self.block.unconditional_shallow_size_of(ops) + self.block.read_with(guard).size_of(ops)

So you'd actually need two traits, or a single trait with two methods, or something.

If we end up measuring enough of these Arc<Locked<T>> things maybe it'll be worth doing that, but for the moment I decided it was simpler just to make the two separate function calls.

@bzbarsky
Copy link
Contributor

So for what it's worth, I tried to implement my suggestion but using a single trait that is automatically implemented for Locked when T is MallocSizeOf, and ran into all sorts of issues with Rust's rules for traits. In particular, since MallocSizeOf is defined in one crate and MallocSizeOfWithGuard in another (so it can see the guard), Rust assumes that a single T can implement both. :(

And if I put MallocSizeOfWithGuard in the malloc_size_of crate, then making it possible for it to take a guard is rocket science. :(

@nnethercote
Copy link
Contributor Author

I can believe it. One of the motivations for overhauling MallocSizeOf in https://bugzilla.mozilla.org/show_bug.cgi?id=1398737 was to make it more flexible in the cases where things don't fit neatly into traits. Hence the ability to do shallow measurements of types like Box, Arc, Vec, HashMap, etc. That's a big problem with the existing HeapSizeOf crate that Servo uses.

@ionutgoldan
Copy link

Looks like this merge brought some improvements:

== Change summary for alert #9405 (as of September 12 2017 14:45 UTC) ==

Improvements:

4% Heap Unclassified summary windows10-64 opt 48,812,667.91 -> 46,759,664.87
4% Heap Unclassified summary windows7-32 opt 41,291,712.81 -> 39,557,429.30
4% Heap Unclassified summary windows7-32 pgo 41,090,548.03 -> 39,442,801.26
3% Heap Unclassified summary linux64-stylo-sequential opt stylo-sequential56,742,017.56 -> 54,809,147.79
3% Heap Unclassified summary windows10-64 pgo 48,751,513.46 -> 47,116,870.64
3% Heap Unclassified summary linux64 opt 57,025,569.58 -> 55,134,734.22

For up to date results, see: https://treeherder.mozilla.org/perf.html#/alerts?id=9405

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.

None yet

7 participants