layout: Improve and expand category names for layout profiling (#37833)

This improves naming of layout categories and adds tracing for each
layout phase.

Testing: This just adds / adjusts profiling categories, so doesn't need
tests.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
Martin Robinson 2025-07-02 17:02:56 +02:00 committed by GitHub
parent afdd9778e5
commit 19b5e14851
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 33 additions and 20 deletions

View file

@ -45,6 +45,7 @@ pub struct BoxTree {
}
impl BoxTree {
#[servo_tracing::instrument(name = "Box Tree Construction", skip_all)]
pub(crate) fn construct(context: &LayoutContext, root_element: ServoLayoutNode<'_>) -> Self {
let boxes = construct_for_root_element(context, root_element);
@ -191,6 +192,7 @@ fn construct_for_root_element(
}
impl BoxTree {
#[servo_tracing::instrument(name = "Fragment Tree Construction", skip_all)]
pub(crate) fn layout(
&self,
layout_context: &LayoutContext,

View file

@ -440,7 +440,7 @@ impl Layout for LayoutThread {
fn reflow(&mut self, reflow_request: ReflowRequest) -> Option<ReflowResult> {
time_profile!(
profile_time::ProfilerCategory::LayoutPerform,
profile_time::ProfilerCategory::Layout,
self.profiler_metadata(),
self.time_profiler_chan.clone(),
|| self.handle_reflow(reflow_request),
@ -821,17 +821,24 @@ impl LayoutThread {
.restyle
.as_ref()
.expect("Should not get here if there is not restyle.");
let dirty_root = unsafe {
let recalc_style_traversal;
let dirty_root;
{
#[cfg(feature = "tracing")]
let _span = tracing::trace_span!("Styling", servo_profiling = true).entered();
let original_dirty_root = unsafe {
ServoLayoutNode::new(&restyle.dirty_root.unwrap())
.as_element()
.unwrap()
};
let recalc_style_traversal = RecalcStyle::new(&layout_context);
recalc_style_traversal = RecalcStyle::new(&layout_context);
let token = {
let shared =
DomTraversal::<ServoLayoutElement>::shared_context(&recalc_style_traversal);
RecalcStyle::pre_traverse(dirty_root, shared)
RecalcStyle::pre_traverse(original_dirty_root, shared)
};
if !token.should_traverse() {
@ -839,8 +846,8 @@ impl LayoutThread {
return (RestyleDamage::empty(), IFrameSizes::default());
}
let dirty_root: ServoLayoutNode =
driver::traverse_dom(&recalc_style_traversal, token, rayon_pool).as_node();
dirty_root = driver::traverse_dom(&recalc_style_traversal, token, rayon_pool).as_node();
}
let root_node = root_element.as_node();
let mut damage = compute_damage_and_repair_style(&layout_context.style_context, root_node);
@ -909,6 +916,7 @@ impl LayoutThread {
(damage, std::mem::take(&mut *iframe_sizes))
}
#[servo_tracing::instrument(name = "Overflow Calculation", skip_all)]
fn calculate_overflow(&self, damage: RestyleDamage) {
if !damage.contains(RestyleDamage::RECALCULATE_OVERFLOW) {
return;
@ -927,6 +935,7 @@ impl LayoutThread {
self.need_new_stacking_context_tree.set(true);
}
#[servo_tracing::instrument(name = "Stacking Context Tree Construction", skip_all)]
fn build_stacking_context_tree(&self, reflow_request: &ReflowRequest, damage: RestyleDamage) {
if !ReflowPhases::necessary(&reflow_request.reflow_goal)
.contains(ReflowPhases::StackingContextTreeConstruction)
@ -999,6 +1008,7 @@ impl LayoutThread {
/// Build the display list for the current layout and send it to the renderer. If no display
/// list is built, returns false.
#[servo_tracing::instrument(name = "Display List Construction", skip_all)]
fn build_display_list(
&self,
reflow_request: &ReflowRequest,

View file

@ -92,6 +92,7 @@ where
}
}
#[servo_tracing::instrument(skip_all)]
pub(crate) fn compute_damage_and_repair_style(
context: &SharedStyleContext,
node: ServoLayoutNode<'_>,

View file

@ -66,7 +66,7 @@ pub enum ProfilerCategory {
Compositing = 0x00,
/// The script thread is doing layout work.
LayoutPerform = 0x10,
Layout = 0x10,
ImageSaving = 0x51,
ScriptAttachLayout = 0x60,
@ -126,7 +126,7 @@ impl ProfilerCategory {
pub const fn variant_name(&self) -> &'static str {
match self {
ProfilerCategory::Compositing => "Compositing",
ProfilerCategory::LayoutPerform => "LayoutPerform",
ProfilerCategory::Layout => "Layout",
ProfilerCategory::ImageSaving => "ImageSaving",
ProfilerCategory::ScriptAttachLayout => "ScriptAttachLayout",
ProfilerCategory::ScriptConstellationMsg => "ScriptConstellationMsg",