layout: optimize the propagation and cleanup of RestyleDamage (#38199)

This change optimizes `RestyleDamage` propagation and cleanup to reduce
unnecessary box reconstruction and relayouts, while preventing damage
from the current reflow affecting subsequent ones. Improvements include:
- For box damage caused by `NodeDamage`, `RestyleDamage::RELAYOUT` is no
longer marked immediately—avoiding erroneous propagation of
`LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN` to descendants during
`RestyleDamage` propagation.
- Clearing damage for nodes whose boxes will be preserved, preventing it
from carrying over to the next reflow and increasing its workload.

Testing: This should not change observable behavior and is thus covered
by existing WPT tests. Although Servo lacks performance test cases,
manual testing shows that this modification reduces reflow time by
nearly 250ms, representing a decrease of approximately 25%.

Signed-off-by: sharpshooter_pt <ibluegalaxy_taoj@163.com>
This commit is contained in:
JoeDow 2025-07-25 20:10:16 +08:00 committed by GitHub
parent 87bbe0b374
commit 9d29017c0d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 11 deletions

View file

@ -21,12 +21,11 @@ bitflags! {
impl LayoutDamage {
pub fn recollect_box_tree_children() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits()) |
RestyleDamage::RELAYOUT
RestyleDamage::from_bits_retain(LayoutDamage::RECOLLECT_BOX_TREE_CHILDREN.bits())
}
pub fn rebuild_box_tree() -> RestyleDamage {
RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits()) | RestyleDamage::RELAYOUT
RestyleDamage::from_bits_retain(LayoutDamage::REBUILD_BOX.bits())
}
pub fn has_box_damage(&self) -> bool {