Layout: minor optimizations and bugfix for non-functional details (#38197)

This change adds some minor optimizations and bugfix for non-functional
details with seperated commits:
- fix the omission that stop use `Rayon` in single-thread mode
- add trace for incremental box tree construction
- fix the bug that failed to skip reflow entirely when there is no need
for `restyle` and a fragment tree has already been built.
- add trace for stylist preparation during reflow. In certain scenarios,
this phase might take up a significant amount of time, such as when
there are a large number of shadow trees.

Testing: This should not change observable behavior and is thus covered
by existing WPT tests.

---------

Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This commit is contained in:
JoeDow 2025-07-22 18:56:52 +08:00 committed by GitHub
parent 19a121e829
commit 8a1cc69717
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View file

@ -1179,7 +1179,11 @@ fn do_initial_flex_line_layout<'items>(
// We didn't reach the end of the last line, so add all remaining items there. // We didn't reach the end of the last line, so add all remaining items there.
lines.push((items, line_size_so_far)); lines.push((items, line_size_so_far));
lines.par_drain(..).map(construct_line).collect() if flex_context.layout_context.use_rayon {
lines.par_drain(..).map(construct_line).collect()
} else {
lines.drain(..).map(construct_line).collect()
}
} }
/// The result of splitting the flex items into lines using their intrinsic sizes and doing an /// The result of splitting the flex items into lines using their intrinsic sizes and doing an

View file

@ -376,6 +376,7 @@ impl<'dom> IncrementalBoxTreeUpdate<'dom> {
}) })
} }
#[servo_tracing::instrument(name = "Box Tree Update From Dirty Root", skip_all)]
fn update_from_dirty_root(&self, context: &LayoutContext) { fn update_from_dirty_root(&self, context: &LayoutContext) {
let contents = ReplacedContents::for_element(self.node, context) let contents = ReplacedContents::for_element(self.node, context)
.map_or_else(|| NonReplacedContents::OfElement.into(), Contents::Replaced); .map_or_else(|| NonReplacedContents::OfElement.into(), Contents::Replaced);

View file

@ -589,7 +589,7 @@ impl LayoutThread {
return false; return false;
} }
// We always need to at least build a fragment tree. // We always need to at least build a fragment tree.
if !self.fragment_tree.borrow().is_none() { if self.fragment_tree.borrow().is_none() {
return false; return false;
} }
@ -710,6 +710,7 @@ impl LayoutThread {
(viewport_changed && had_used_viewport_units) || theme_changed (viewport_changed && had_used_viewport_units) || theme_changed
} }
#[servo_tracing::instrument(skip_all)]
fn prepare_stylist_for_reflow<'dom>( fn prepare_stylist_for_reflow<'dom>(
&mut self, &mut self,
reflow_request: &ReflowRequest, reflow_request: &ReflowRequest,