Auto merge of #17192 - mbrubeck:layout, r=pcwalton

Parallel layout optimizations

This takes some of the optimizations made to parallel styling in #16971 and applies them to parallel layout.  Specifically:

* Reduce the chunk size, to increase chances for parallelism on trees with small fan-out.
* Reduce allocations by using SmallVec.
* Reduce task switching by processing up to one chunk of children within the same rayon task as the parent.

This cuts the "Primary Layout Pass" time in **half** on the MySpace page from [tp5n], and on my other real-world test pages it is a small improvement or close to no change.

[tp5n]: https://wiki.mozilla.org/Buildbot/Talos/Tests#tp5n_pages_set

---
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes do not require tests because they affect performance only

<!-- 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/17192)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-06-07 19:57:57 -07:00 committed by GitHub
commit c0f3ec8780
2 changed files with 34 additions and 13 deletions

View file

@ -443,7 +443,11 @@ impl LayoutThread {
let configuration =
rayon::Configuration::new().num_threads(layout_threads);
let parallel_traversal = rayon::ThreadPool::new(configuration).ok();
let parallel_traversal = if layout_threads > 1 {
Some(rayon::ThreadPool::new(configuration).expect("ThreadPool creation failed"))
} else {
None
};
debug!("Possible layout Threads: {}", layout_threads);
// Create the channel on which new animations can be sent.
@ -1074,7 +1078,7 @@ impl LayoutThread {
debug!("layout: processing reflow request for: {:?} ({}) (query={:?})",
element, self.url, data.query_type);
debug!("{:?}", ShowSubtree(element.as_node()));
trace!("{:?}", ShowSubtree(element.as_node()));
let initial_viewport = data.window_size.initial_viewport;
let old_viewport_size = self.viewport_size;