Open Bug 1456281 Opened 6 years ago Updated 1 month ago

Consider not calling AllocateGeometry and ComputeInvalidationRegion for items <svg> elements

Categories

(Core :: Graphics: WebRender, defect, P2)

defect

Tracking

()

Tracking Status
firefox63 --- affected

People

(Reporter: mstange, Assigned: jrmuizel)

References

(Depends on 2 open bugs, Blocks 1 open bug)

Details

Attachments

(1 file)

SVGs commonly have a large number of display items. Any work that we do per-item has a potentially big performance impact. Here's a profile of moving my mouse on https://www.article19.org/xpa-17-metric/ , focused on mozilla::layers::DIGroup::ComputeGeometryChange: https://perfht.ml/2vEfoLF

As far as I know, SVG elements do not make use of DLBI. Anything that affects the appearance of something inside <svg> invalidates the frame. The only exceptions I can think of are:
 - async image decoding invalidation for <svg:image> (?)
 - <foreignObject>

It would be nice if we could avoid allocating geometries for DLBI for SVG items.
foreignObject should be easy to exclude from that optimization.

Matt, can you think of other reasons why we might need to call AllocateGeometry and ComputeInvalidationRegion?
Here's nsDisplaySVGGeometry::ComputeInvalidationRegion, it doesn't do anything interesting other than calling ShouldInvalidateToSyncDecodeImages:
https://searchfox.org/mozilla-central/rev/8f06c1b9a080b84435a2906e420fe102e1ed780b/layout/svg/SVGGeometryFrame.cpp#137-152
Flags: needinfo?(matt.woodrow)
Looks like nsDisplaySVGGeometry is using nsDisplayItemGenericImageGeometry, which also checks for border rect changes.

If we're confident that SVG will invalidate the frame for border rect changes (which makes sense since we don't really reflow SVG), then we should be able to conditionally allocate the geometry if we actually have an image to paint.

Can you think of anything else we need here Jonathan?
Flags: needinfo?(matt.woodrow) → needinfo?(jwatt)
(In reply to Markus Stange [:mstange] from comment #0)
> As far as I know, SVG elements do not make use of DLBI.

It's been five years and my memories are hazy, but unless something's changed or we have a different understanding of what precisely "DLBI" means, I thought SVG has been relying on DLBI since bug 827915.

(In reply to Matt Woodrow (:mattwoodrow) from comment #1)
> Looks like nsDisplaySVGGeometry is using nsDisplayItemGenericImageGeometry,
> which also checks for border rect changes.
> 
> If we're confident that SVG will invalidate the frame for border rect
> changes (which makes sense since we don't really reflow SVG),

We don't reflow in the sense of box model reflow, but we have a reflow-lite that has to set mRect (see SVGGeometryFrame::ReflowSVG) and we depend on mRect having useful values for DLBI to work.
Flags: needinfo?(jwatt)
Flags: needinfo?(matt.woodrow)
Comment on attachment 8972441 [details]
Bug 1456281. Ensure that we don't need to call ComputeInvalidationRegion.

https://reviewboard.mozilla.org/r/241042/#review246826

What about async image decoding?
Comment on attachment 8972441 [details]
Bug 1456281. Ensure that we don't need to call ComputeInvalidationRegion.

https://reviewboard.mozilla.org/r/241042/#review247740
Attachment #8972441 - Flags: review?(mstange)
Matt, Markus, I'm guessing we don't need to fix this for 61?
Flags: needinfo?(mstange)
This optimization idea is mostly targeted at WebRender, so there's no rush to fix this.
Flags: needinfo?(mstange)
Depends on: 1480132
Assignee: nobody → jmuizelaar

Moving to p2 because no activity for at least 24 weeks.
See How Do You Triage for more information

Priority: P1 → P2

Redirect a needinfo that is pending on an inactive user to the triage owner.
:gw, since the bug has high priority, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(matt.woodrow) → needinfo?(gwatson)

This was the patch: https://hg.mozilla.org/mozreview/gecko/rev/17cb6969152eecb590d8746a0156dceed571a3a9

I had completely forgotten about this idea. It seems worthwhile.

Flags: needinfo?(gwatson) → needinfo?(jmuizelaar)

This fails layout/reftests/bugs/220165-1.svg

Ah, that file tests foreignObject, which we would need to special case (see comment 0). Too bad the patch didn't include the special case, now we actually have to do some thinking ourselves.

layout/reftests/svg/baseline-middle-01.svg also fills

After disabling the broken sync image decoding invalidation the assertion still fails on tests like layout/reftests/svg/text/mask-applied.svg because SVG reflow doesn't actually mark the frame as invalid because as of bug 802628 it just relies on DLBI

Depends on: 1773502

After making SVG reflow mark frames as invalid:

diff --git a/layout/svg/SVGContainerFrame.cpp b/layout/svg/SVGContainerFrame.cpp
index 38f4bf7a79470..ae1741d92a9ba 100644
--- a/layout/svg/SVGContainerFrame.cpp
+++ b/layout/svg/SVGContainerFrame.cpp
@@ -359,20 +359,21 @@ void SVGDisplayContainerFrame::ReflowSVG() {
     // nsChangeHint_UpdateEffects):
     SVGObserverUtils::UpdateEffects(this);
   }

   FinishAndStoreOverflow(overflowRects, mRect.Size());

   // Remove state bits after FinishAndStoreOverflow so that it doesn't
   // invalidate on first reflow:
   RemoveStateBits(NS_FRAME_FIRST_REFLOW | NS_FRAME_IS_DIRTY |
                   NS_FRAME_HAS_DIRTY_CHILDREN);
+  InvalidateFrame();
 }

 void SVGDisplayContainerFrame::NotifySVGChanged(uint32_t aFlags) {
   MOZ_ASSERT(aFlags & (TRANSFORM_CHANGED | COORD_CONTEXT_CHANGED),
              "Invalidation logic may need adjusting");

   if (aFlags & TRANSFORM_CHANGED) {
     // make sure our cached transform matrix gets (lazily) updated
     mCanvasTM = nullptr;
   }

We run into invalidations caused by transform changes with nsDisplayTransformGeometry in layout/reftests/svg/dynamic-text-06.svg. We could solve these by having a frame flag for container properties (transform, opacity, blendmode) changes.

Severity: normal → S3
Blocks: wr-blob-perf
No longer blocks: stage-wr-next
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: