layout: Stop using Rayon in single-threaded mode (#37832)

In layout, some parts of the code were still using parallel iterators
from Rayon even when single-thread layout was activated. This change
modifies those parts to use non-parallel iterators when
`LayoutContext::use_rayon` is not active.

Testing: It's very hard to make an automated test for this, but I've
manually
verified this by building with tracing and observing that layout runs
only on
a single thread now when loading https://servo.org.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-07-02 14:44:43 +02:00 committed by GitHub
parent da364f7a61
commit 647122d0f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 197 additions and 144 deletions

View file

@ -1221,14 +1221,25 @@ impl InitialFlexLineLayout<'_> {
);
// https://drafts.csswg.org/css-flexbox/#algo-cross-item
let layout_results = items
.par_iter()
.zip(&item_used_main_sizes)
.map(|(item, used_main_size)| {
item.layout(*used_main_size, flex_context, None, None)
.unwrap()
})
.collect::<Vec<_>>();
let layout_results: Vec<_> = if flex_context.layout_context.use_rayon {
items
.par_iter()
.zip(&item_used_main_sizes)
.map(|(item, used_main_size)| {
item.layout(*used_main_size, flex_context, None, None)
.unwrap()
})
.collect()
} else {
items
.iter()
.zip(&item_used_main_sizes)
.map(|(item, used_main_size)| {
item.layout(*used_main_size, flex_context, None, None)
.unwrap()
})
.collect()
};
let items: Vec<_> = izip!(
items.into_iter(),