Closed Bug 1330570 Opened 7 years ago Closed 7 years ago

Allocate DisplayItemData in the presshell arena

Categories

(Core :: Web Painting, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla55
Tracking Status
firefox55 --- fixed

People

(Reporter: mstange, Assigned: bas.schouten)

References

(Blocks 1 open bug)

Details

Attachments

(2 files)

We access these a lot during layer building. Moving them to the presshell arena might improve cache locality.

DisplayItemData objects are reference counted. They are stored in an nsTArray which is stored as a frame property. For best results, we also need to allocate the nsTArray and its internal buffers in the arena, as well as the FramePropertyTable (bug 1330558).
Here's a first stab at this, I still need to do some solid profiling to provide evidence for its efficacy. Let me know what you think.
Attachment #8827218 - Flags: feedback?(mstange)
Attachment #8827218 - Flags: feedback?(matt.woodrow)
Comment on attachment 8827218 [details] [diff] [review]
Move DisplayItemData into the PresShell arena

Review of attachment 8827218 [details] [diff] [review]:
-----------------------------------------------------------------

Seems totally reasonable. Looking forward to perf data!
Attachment #8827218 - Flags: feedback?(matt.woodrow) → feedback+
Comment on attachment 8827218 [details] [diff] [review]
Move DisplayItemData into the PresShell arena

Review of attachment 8827218 [details] [diff] [review]:
-----------------------------------------------------------------

Looks good! This won't help with display list building times (because display list building doesn't use DisplayItemData), but it should help with layer building times.

The AssertDisplayItemData stuff is instrumentation that was supposed to help me debug a crash (bug 1141089) but I never figured out what was happening. Maybe you have ideas, now that you've looked at this code a bit? In any case, we have enough crash reports to tell us that sAliveDisplayItemDatas->Contains(aData) is the check that's failing, so we could just remove the instrumentation. That should help get the cache misses down.
In fact, I'd be surprised if this patch helps perf on its own as long as AssertDisplayItemData still exists.
Attachment #8827218 - Flags: feedback?(mstange) → feedback+
Comment on attachment 8827218 [details] [diff] [review]
Move DisplayItemData into the PresShell arena

Review of attachment 8827218 [details] [diff] [review]:
-----------------------------------------------------------------

::: layout/painting/FrameLayerBuilder.h
@@ +72,5 @@
> +    return aPresContext->PresShell()->
> +      AllocateByObjectID(eArenaObjectID_DisplayItemData, sz);
> +  }
> +
> +  // These two methods are for use by ArenaRefPtr.

It looks like the rest of this patch just uses regular RefPtrs, and not ArenaRefPtr. Have you found out what ArenaRefPtr is for?
(In reply to Markus Stange [:mstange] from comment #4)
> Comment on attachment 8827218 [details] [diff] [review]
> Move DisplayItemData into the PresShell arena
> 
> Review of attachment 8827218 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: layout/painting/FrameLayerBuilder.h
> @@ +72,5 @@
> > +    return aPresContext->PresShell()->
> > +      AllocateByObjectID(eArenaObjectID_DisplayItemData, sz);
> > +  }
> > +
> > +  // These two methods are for use by ArenaRefPtr.
> 
> It looks like the rest of this patch just uses regular RefPtrs, and not
> ArenaRefPtr. Have you found out what ArenaRefPtr is for?

I think I did but I no longer remember.. I think it had something to do with allocation and deallocation policy :s.
Blocks: 1331928
Comment on attachment 8865438 [details]
Bug 1330570: Allocate DisplayItemData into the PresShell Arena.

https://reviewboard.mozilla.org/r/137108/#review140338

r=me with either using ArenaRefPtr, or dropping support for it.

::: layout/painting/FrameLayerBuilder.h:73
(Diff revision 1)
> +  void Invalidate() { mIsInvalid = true; }
> +  void ClearAnimationCompositorState();
> +
> +  static DisplayItemData* AssertDisplayItemData(DisplayItemData* aData);
> +
> +  void* operator new(size_t sz, nsPresContext* aPresContext)

Seems like most of this new code is basically identical boilterplate to what's in nsStyleContext. Might be worth moving it to a #define so it can be shared?

::: layout/painting/FrameLayerBuilder.cpp:137
(Diff revision 1)
>    GetMaskLayerImageCache()->Sweep();
>    MOZ_COUNT_DTOR(FrameLayerBuilder);
>  }
>  
> -FrameLayerBuilder::DisplayItemData::DisplayItemData(LayerManagerData* aParent, uint32_t aKey,
> +DisplayItemData::DisplayItemData(LayerManagerData* aParent, uint32_t aKey,
>                                                      Layer* aLayer, nsIFrame* aFrame)

Alignment

::: layout/painting/FrameLayerBuilder.cpp:219
(Diff revision 1)
>  }
>  
>  void
> -FrameLayerBuilder::DisplayItemData::BeginUpdate(Layer* aLayer, LayerState aState,
> +DisplayItemData::BeginUpdate(Layer* aLayer, LayerState aState,
>                                                  uint32_t aContainerLayerGeneration,
>                                                  nsDisplayItem* aItem /* = nullptr */)

Alignment here too.

::: layout/painting/FrameLayerBuilder.cpp:396
(Diff revision 1)
>     */
>    LayerManager *mLayerManager;
>  #ifdef DEBUG_DISPLAY_ITEM_DATA
>    LayerManagerData *mParent;
>  #endif
> -  nsTHashtable<nsRefPtrHashKey<FrameLayerBuilder::DisplayItemData> > mDisplayItems;
> +  nsTHashtable<nsRefPtrHashKey<DisplayItemData> > mDisplayItems;

We could use ArenaRefPtr here instead of normal RefPtr.

ArenaRefPtr is a 'weak' pointer, that clears its reference if the arena gets destroyed while there are still outstanding references to items within it.

That should never actually happen though, since we should always destroy all frames first, and the frame dtor should clean up any DisplayItemData objects.

If we're not going to use ArenaRefPtr though, we should probably switch to PRES_ARENA_OBJECT_WITHOUT_ARENAREFPTR_SUPPORT and go back to normal refcounting and not pay for the extra tracking.
Attachment #8865438 - Flags: review?(matt.woodrow) → review+
Pushed by bschouten@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/9483bb6d8ce6
Allocate DisplayItemData into the PresShell Arena. r=mattwoodrow
Backout by cbook@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/df9358a0469a
Backed out changeset 9483bb6d8ce6 for test failures in test_selection_move_commands.html | cmd_scrollBottom - -300 should equal -300
Flags: needinfo?(bas)
Pushed by bschouten@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/129ab771d0ad
Allocate DisplayItemData into the PresShell Arena. r=mattwoodrow
https://hg.mozilla.org/mozilla-central/rev/129ab771d0ad
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: