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 upStore ClipScrollNodes in a vector #2449
Conversation
|
Sorry for the size of this PR. It's difficult to make such a deep change without changing a lot of code. Here is the Gecko try job for this change: https://treeherder.mozilla.org/#/jobs?repo=try&revision=8950bf1f433b3fd3b71b5cb526d9cb71fea98770&selectedJob=163434876 |
|
@staktrace Heads up about the Gecko changes. I had to modify gfx/webrender_bindings/webrender_ffi_generated.h manually because it seems that cbindgen has trouble with the current WebRender source tree. |
|
I feel like the gecko-side changes should either assert that u64 and usize have the same number of bits (which might not actually be true on all platforms) or better, we should replace uint64_t with size_t wherever we're keeping WR clipids in C++. This is probably hard to do at the moment but will be a lot simpler if I land my changes for using ClipChains (but that's blocked on #2388). |
|
Looks like a decent optimization, at the cost of increased re-direction complexity of the code. Reviewed 12 of 12 files at r1. webrender/src/clip_scroll_tree.rs, line 135 at r1 (raw file):
didn't we have constants defined for those special indices somewhere? webrender/src/clip_scroll_tree.rs, line 466 at r1 (raw file):
why is this removed? webrender/src/clip_scroll_tree.rs, line 505 at r1 (raw file):
I'd refactor that code into: if let Some(ref mut empty_node) = self.nodes.get_mut(index.0) {
*empty_node = node;
return
}
self.nodes.reserve_exact(index.0 + 1 - self.nodes.len());
self.nodes.extend((self.nodes.len() .. index.0).map(|_| ClipScrollNode::empty());
self.nodes.push(node);webrender/src/clip_scroll_tree.rs, line 511 at r1 (raw file):
this is incorrect usage of webrender/src/frame.rs, line 49 at r1 (raw file):
need to comment cleanly the difference between webrender/src/frame.rs, line 54 at r1 (raw file):
nit: webrender/src/frame.rs, line 58 at r1 (raw file):
the whole implementation can probably be replaced by webrender/src/frame.rs, line 60 at r1 (raw file):
what's the lifetime of those fields? I don't see them being reset webrender/src/frame.rs, line 83 at r1 (raw file):
nit: maybe webrender/src/frame.rs, line 109 at r1 (raw file):
not sure if this is truly webrender/src/hit_test.rs, line 130 at r1 (raw file):
nit: use webrender_api/src/display_item.rs, line 771 at r1 (raw file):
This is significantly less used now. We should take another look at the type and see if it's still needed, or maybe rename it to something more verbose webrender_api/src/display_list.rs, line 518 at r1 (raw file):
clip chain doesn't count for total clips? Comments from Reviewable |
|
Review status: all files reviewed at latest revision, 13 unresolved discussions. webrender/src/clip_scroll_tree.rs, line 135 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
We have constants for ClipId, but they are semantically different. This is a good idea though, so I've added constants for these ones in webrender/src/clip_scroll_tree.rs, line 466 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
I had fixed this, but the fix was sitting uncommitted in my working tree. webrender/src/clip_scroll_tree.rs, line 505 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Okay. This seems fine to me as well. I had to make a couple minor changes to make the borrow checker happy. I've also added a comment here explaining why we have to do this instead of webrender/src/clip_scroll_tree.rs, line 511 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Nice catch. webrender/src/frame.rs, line 49 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
I added comments for all the members and renamed webrender/src/frame.rs, line 54 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/src/frame.rs, line 58 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/src/frame.rs, line 60 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
This lives as long as the FlattenContext which is only alive as long as display list flattening is happening. This struct is used only be used once and then discarded. webrender/src/frame.rs, line 83 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Hrm. I'm not sure because this is doing two things getting the index and caching it. I'm not sure if webrender/src/frame.rs, line 109 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender/src/hit_test.rs, line 130 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
Done. webrender_api/src/display_item.rs, line 771 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
I confirmed that these are all still necessary. webrender_api/src/display_list.rs, line 518 at r1 (raw file): Previously, kvark (Dzmitry Malyshau) wrote…
ClipChains don't have corresponding ClipScrollNodes so they don't increase the count. Comments from Reviewable |
|
@staktrace I modified the Gecko-side patch to store size_t for ids that correspond to ClipScrollNodes. It wasn't a lot of work (though did require me to edit more of the auto-generated bindings by hand). The Gecko try for this modified version is here: https://treeherder.mozilla.org/#/jobs?repo=try&revision=acdbaae3df471bd15eb355520144af790a5e9b13 I still plan to look at #2388 today, but maybe it doesn't need to block this change? |
4df8a29
to
b76ae01
|
Looks like your try push has compilation failures so the patch might need some tweaking. Also FYI we have a new cbindgen version posted which should allow you to regenerate the bindings without manual tinkering. You'll need to install/run it with rust nightly though:
Agreed that #2388 doesn't need to block this - but I'd like to review the final gecko-side changes for this PR once you have the compilation failures sorted out. Assuming it's a straightforward replacement of uint64_t to size_t in the relevant places it should be fine. |
|
@staktrace Thanks for the information about cbindgen. I've kicked off another Gecko try that should hopefully fix the build failures on 32-bit Linux: https://treeherder.mozilla.org/#/jobs?repo=try&revision=cd9b9ede957425da328fe7dd38fc215dc7475fbd |
|
I also confirmed that cbindgen didn't materially change code related to my change other than correcting a comment and fixing the implementation of the == operator override for BuiltDisplayList. |
|
Reviewed 4 of 4 files at r2. Comments from Reviewable |
|
@bors-servo r+ |
|
|
|
|
|
|
Instead of storing ClipScrollNodes in a HashMap, store them in a vector. This removes the CPU cost of accessing any particular ClipScrollNode. In its place is a somewhat clunky system of translating a ClipId into a ClipScrollIndex. These are allocated based on the total number of ClipIds per display list, so the translation should be fairly cheap. A per-pipeline offset and cache is stored, so the number of HashMap lookups for display list flattening should be the same order as the number of pipelines. The big trade off here is that when descending into iframes, we need to allocate space in the ClipScrollNode array ahead of time. If these memory allocations turn out to be a problem, we can modify the code to try to mutate existing nodes or to use a more complicated system of sub vectors or slices.
b76ae01
to
b548082
|
@kvark @staktrace Thanks for looking at this PR. I've rebased and will land it now. |
|
@bors-servo r=kvark |
|
|
Store ClipScrollNodes in a vector Instead of storing ClipScrollNodes in a HashMap, store them in a vector. This removes the CPU cost of accessing any particular ClipScrollNode. In its place is a somewhat clunky system of translating a ClipId into a ClipScrollIndex. These are allocated based on the total number of ClipIds per display list, so the translation should be fairly cheap. A per-pipeline offset and cache is stored, so the number of HashMap lookups for display list flattening should be the same order as the number of pipelines. The big trade off here is that when descending into iframes, we need to allocate space in the ClipScrollNode array ahead of time. If these memory allocations turn out to be a problem, we can modify the code to try to mutate existing nodes or to use a more complicated system of sub vectors or slices. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/webrender/2449) <!-- Reviewable:end -->
|
|
mrobinson commentedFeb 21, 2018
•
edited by larsbergstrom
Instead of storing ClipScrollNodes in a HashMap, store them in a vector.
This removes the CPU cost of accessing any particular ClipScrollNode. In
its place is a somewhat clunky system of translating a ClipId into a
ClipScrollIndex. These are allocated based on the total number of
ClipIds per display list, so the translation should be fairly cheap. A
per-pipeline offset and cache is stored, so the number of HashMap
lookups for display list flattening should be the same order as the
number of pipelines.
The big trade off here is that when descending into iframes, we need to
allocate space in the ClipScrollNode array ahead of time. If these
memory allocations turn out to be a problem, we can modify the code to
try to mutate existing nodes or to use a more complicated system of sub
vectors or slices.
This change is