Repository: servo/servo
File: components/layout/display_list/mod.rs (Rust)

Code before:
            paint_highlight(
                BORDER_BOX_HIGHLIGHT_COLOR,
                box_fragment.border_rect(),
                box_fragment.border.to_webrender(),
            );
            paint_highlight(
                MARGIN_BOX_HIGHLIGHT_COLOR,
                box_fragment.margin_rect(),
                box_fragment.margin.to_webrender(),
            );
        }
    }

    #[inline]
    fn collect_paint_candidate(
        &mut self,
        contentful_paint_type: ContentfulPaintType,
        lcp_candidate_id: LCPCandidateID,
        clip_rect: LayoutRect,
        bounds: LayoutRect,
    ) {
        if let Some(paint_collector) = &mut self.paint_candidate_collector {
            let transform = self
                .paint_info
                .scroll_tree
                .cumulative_node_to_root_transform(self.current_scroll_node_id);
            let area = paint_collector.candidate_size(clip_rect, bounds, transform);
            if area == 0 {
                return;
            }

            // Collect LCP candidate only if LCP feature is enabled
            if pref!(largest_contentful_paint_enabled) {
                paint_collector.add_or_update_candidate(LCPCandidate::new(
                    lcp_candidate_id,
                    contentful_paint_type,
                    area,
                ));
            }
        }
        // Mark the page as contentful when we have a valid paint candidate
        self.mark_is_contentful();
    }
}

impl InspectorHighlight {
    fn register_fragment_of_highlighted_dom_node(
        &mut self,
        fragment: &Fragment,
        spatial_id: SpatialId,
        clip_chain_id: ClipChainId,

Review comment (performance):
This is the expensive part of the LCP calculation as it's calculating all transformations to the root viewport readily. In many cases this can be delayed or avoided entirely for display lists. This is the thing that should be avoided when the preference is disabled.

Code after:
                box_fragment.border_rect(),
                box_fragment.border.to_webrender(),
            );
            paint_highlight(
                MARGIN_BOX_HIGHLIGHT_COLOR,
                box_fragment.margin_rect(),
                box_fragment.margin.to_webrender(),
            );
        }
    }

    fn check_for_contentful_paint(&mut self, bounds: LayoutRect, clip_rect: LayoutRect) {
        if self
            .paint_timing_handler
            .check_bounding_rect(bounds, clip_rect)
        {
            self.mark_is_contentful();
        }
    }

    fn check_for_lcp_candidate(
        &mut self,
        lcp_candidate_id: LCPCandidateID,
        clip_rect: LayoutRect,
        bounds: LayoutRect,
    ) {
        if !pref!(largest_contentful_paint_enabled) {
            return;
        }

        let transform = self
            .paint_info
            .scroll_tree
            .cumulative_node_to_root_transform(self.current_scroll_node_id);

        self.paint_timing_handler.update_lcp_candidate(
            lcp_candidate_id,
            bounds,
            clip_rect,
            transform,
        );
    }
}

impl InspectorHighlight {
    fn register_fragment_of_highlighted_dom_node(
        &mut self,
        fragment: &Fragment,
        spatial_id: SpatialId,
        clip_chain_id: ClipChainId,
        containing_block: &PhysicalRect<Au>,