mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
Reduce allocations in layout_block_level_children_in_parallel (#35781)
This function showed up as a top producer of allocations (around 10% of all allocations). Allocating the vector once upfront and using `collect_into_vec` removes any intermediate allocations. This approach is also recommended by the rayon documentation: https://docs.rs/rayon/1.10.0/rayon/iter/trait.ParallelIterator.html#method.collect Signed-off-by: Jonathan Schwender <schwenderjonathan@gmail.com>
This commit is contained in:
parent
f594691af9
commit
5533092ab3
1 changed files with 6 additions and 3 deletions
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use app_units::{Au, MAX_AU};
|
use app_units::{Au, MAX_AU};
|
||||||
use inline::InlineFormattingContext;
|
use inline::InlineFormattingContext;
|
||||||
use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
|
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
|
||||||
use servo_arc::Arc;
|
use servo_arc::Arc;
|
||||||
use style::Zero;
|
use style::Zero;
|
||||||
use style::computed_values::clear::T as StyleClear;
|
use style::computed_values::clear::T as StyleClear;
|
||||||
|
@ -662,7 +662,10 @@ fn layout_block_level_children_in_parallel(
|
||||||
) -> Vec<Fragment> {
|
) -> Vec<Fragment> {
|
||||||
let collects_for_nearest_positioned_ancestor =
|
let collects_for_nearest_positioned_ancestor =
|
||||||
positioning_context.collects_for_nearest_positioned_ancestor();
|
positioning_context.collects_for_nearest_positioned_ancestor();
|
||||||
let layout_results: Vec<(Fragment, PositioningContext)> = child_boxes
|
let mut layout_results: Vec<(Fragment, PositioningContext)> =
|
||||||
|
Vec::with_capacity(child_boxes.len());
|
||||||
|
|
||||||
|
child_boxes
|
||||||
.par_iter()
|
.par_iter()
|
||||||
.map(|child_box| {
|
.map(|child_box| {
|
||||||
let mut child_positioning_context =
|
let mut child_positioning_context =
|
||||||
|
@ -676,7 +679,7 @@ fn layout_block_level_children_in_parallel(
|
||||||
);
|
);
|
||||||
(fragment, child_positioning_context)
|
(fragment, child_positioning_context)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect_into_vec(&mut layout_results);
|
||||||
|
|
||||||
layout_results
|
layout_results
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue