Skip to content

[LBSE] Cache visual overflow rect computation#57206

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
nikolaszimmermann:eng/LBSE-Cache-visual-overflow-rect-computation
Feb 4, 2026
Merged

[LBSE] Cache visual overflow rect computation#57206
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
nikolaszimmermann:eng/LBSE-Cache-visual-overflow-rect-computation

Conversation

@nikolaszimmermann
Copy link
Contributor

@nikolaszimmermann nikolaszimmermann commented Jan 25, 2026

4bc53a1

[LBSE] Cache visual overflow rect computation
https://bugs.webkit.org/show_bug.cgi?id=306213

Reviewed by Rob Buis.

SVGBoundingBoxComputation::computeVisualOverflowRect() is expensive and appears
frequently in profiling. This patch ensures the cached visual overflow rect is
properly invalidated when:

1. Style changes affect visual overflow (stroke properties, outline, clip-path,
   mask, filter, marker references)
2. Referenced SVG resource content changes (e.g., a <rect> inside <clipPath>
   changes its geometry)

Add RenderLayerModelObject::invalidateCachedVisualOverflowRect() virtual method
with overrides in RenderSVGModelObject, RenderSVGRoot, and RenderSVGText.

Override RenderSVGResourceContainer::layout() to call repaintAllClients() after
children layout, ensuring clients are notified when resource content changes.

In CSSSVGResourceElementClient::resourceChanged(), always invalidate the cached
visual overflow rect, but skip the repaint call during layout since the existing
post-layout mechanism handles it.

Covered by existing tests.

* Source/WebCore/rendering/ReferencedSVGResources.cpp:
(WebCore::CSSSVGResourceElementClient::resourceChanged):
* Source/WebCore/rendering/RenderLayerModelObject.h:
(WebCore::RenderLayerModelObject::invalidateCachedVisualOverflowRect):
* Source/WebCore/rendering/svg/RenderSVGContainer.cpp:
(WebCore::RenderSVGContainer::layoutChildren):
* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::layout):
* Source/WebCore/rendering/svg/RenderSVGModelObject.cpp:
(WebCore::RenderSVGModelObject::styleDidChange):
* Source/WebCore/rendering/svg/RenderSVGModelObject.h:
(WebCore::RenderSVGModelObject::visualOverflowRectEquivalent const):
* Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp:
(WebCore::RenderSVGResourceContainer::layout):
* Source/WebCore/rendering/svg/RenderSVGResourceContainer.h:
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::layoutChildren):
* Source/WebCore/rendering/svg/RenderSVGRoot.h:
* Source/WebCore/rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::layout):
* Source/WebCore/rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::updatePositionAndOverflow):
* Source/WebCore/rendering/svg/RenderSVGText.h:

Canonical link: https://commits.webkit.org/306815@main

cdb7643

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ✅ 🧪 win-tests
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe
✅ 🧪 ios-wk2-wpt ❌ 🧪 api-mac-debug ✅ 🛠 wpe-libwebrtc
✅ 🧪 api-ios ✅ 🧪 mac-wk1 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-wk2 ❌ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-wk2-stress ✅ 🛠 playstation
✅ 🛠 tv ✅ 🧪 mac-intel-wk2
✅ 🛠 tv-sim ✅ 🛠 mac-safer-cpp
✅ 🛠 watch
✅ 🛠 watch-sim

@nikolaszimmermann nikolaszimmermann self-assigned this Jan 25, 2026
@nikolaszimmermann nikolaszimmermann added the WPE WebKit WebKit WPE component label Jan 25, 2026
@nikolaszimmermann nikolaszimmermann added SVG For bugs in the SVG implementation. and removed WPE WebKit WebKit WPE component labels Jan 25, 2026
@nikolaszimmermann nikolaszimmermann force-pushed the eng/LBSE-Cache-visual-overflow-rect-computation branch from e29d537 to cdb7643 Compare February 3, 2026 12:21
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Feb 3, 2026
Copy link
Contributor

@rwlbuis rwlbuis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM now!

@nikolaszimmermann nikolaszimmermann added merge-queue Applied to send a pull request to merge-queue and removed merging-blocked Applied to prevent a change from being merged labels Feb 4, 2026
https://bugs.webkit.org/show_bug.cgi?id=306213

Reviewed by Rob Buis.

SVGBoundingBoxComputation::computeVisualOverflowRect() is expensive and appears
frequently in profiling. This patch ensures the cached visual overflow rect is
properly invalidated when:

1. Style changes affect visual overflow (stroke properties, outline, clip-path,
   mask, filter, marker references)
2. Referenced SVG resource content changes (e.g., a <rect> inside <clipPath>
   changes its geometry)

Add RenderLayerModelObject::invalidateCachedVisualOverflowRect() virtual method
with overrides in RenderSVGModelObject, RenderSVGRoot, and RenderSVGText.

Override RenderSVGResourceContainer::layout() to call repaintAllClients() after
children layout, ensuring clients are notified when resource content changes.

In CSSSVGResourceElementClient::resourceChanged(), always invalidate the cached
visual overflow rect, but skip the repaint call during layout since the existing
post-layout mechanism handles it.

Covered by existing tests.

* Source/WebCore/rendering/ReferencedSVGResources.cpp:
(WebCore::CSSSVGResourceElementClient::resourceChanged):
* Source/WebCore/rendering/RenderLayerModelObject.h:
(WebCore::RenderLayerModelObject::invalidateCachedVisualOverflowRect):
* Source/WebCore/rendering/svg/RenderSVGContainer.cpp:
(WebCore::RenderSVGContainer::layoutChildren):
* Source/WebCore/rendering/svg/RenderSVGImage.cpp:
(WebCore::RenderSVGImage::layout):
* Source/WebCore/rendering/svg/RenderSVGModelObject.cpp:
(WebCore::RenderSVGModelObject::styleDidChange):
* Source/WebCore/rendering/svg/RenderSVGModelObject.h:
(WebCore::RenderSVGModelObject::visualOverflowRectEquivalent const):
* Source/WebCore/rendering/svg/RenderSVGResourceContainer.cpp:
(WebCore::RenderSVGResourceContainer::layout):
* Source/WebCore/rendering/svg/RenderSVGResourceContainer.h:
* Source/WebCore/rendering/svg/RenderSVGRoot.cpp:
(WebCore::RenderSVGRoot::layoutChildren):
* Source/WebCore/rendering/svg/RenderSVGRoot.h:
* Source/WebCore/rendering/svg/RenderSVGShape.cpp:
(WebCore::RenderSVGShape::layout):
* Source/WebCore/rendering/svg/RenderSVGText.cpp:
(WebCore::RenderSVGText::updatePositionAndOverflow):
* Source/WebCore/rendering/svg/RenderSVGText.h:

Canonical link: https://commits.webkit.org/306815@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/LBSE-Cache-visual-overflow-rect-computation branch from cdb7643 to 4bc53a1 Compare February 4, 2026 23:01
@webkit-commit-queue
Copy link
Collaborator

Committed 306815@main (4bc53a1): https://commits.webkit.org/306815@main

Reviewed commits have been landed. Closing PR #57206 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 4bc53a1 into WebKit:main Feb 4, 2026
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

SVG For bugs in the SVG implementation.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants