Closed Bug 1821935 Opened 2 years ago Closed 2 years ago

gfxContext constructor does always an extra heap allocation for mStateStack

Categories

(Core :: Graphics, defect)

defect

Tracking

()

RESOLVED FIXED
113 Branch
Tracking Status
firefox113 --- fixed

People

(Reporter: smaug, Assigned: jfkthame)

References

(Blocks 1 open bug)

Details

(Whiteboard: [sp3])

Attachments

(1 file)

https://searchfox.org/mozilla-central/rev/2ede53e39955988f98db4369f7ce09614b22104a/gfx/thebes/gfxContext.cpp#55,62
The allocation tends to show up in React-Stockcharts profiles, at least in the ZoomTheChart-sync part.
Could AutoTArray be used in gfxContext?

Summary: gfxContext constructor always does an extra heap allocation for mStateStack → gfxContext constructor does always an extra heap allocation for mStateStack

Looks like we recently fixed similar bug 1812729 and bug 1812774.

Yes, I think this would be reasonable. Many of our gfxContexts are short-lived, stack-allocated instances and don't do any Save/Restore operations, so a single-element auto-array would avoid a separate allocation for these.

Actually, on further consideration I think we can do a bit better. We're constantly accessing CurrentState(), which with the existing array implementation (whether the existing nsTArray or an AutoTArray) involves looking up the current array length, and then indexing by mLength-1 to read the last element. We can streamline all these accesses by storing the current AzureState directly in gfxContext, and only pushing it to an array when we do a Save() operation.

This will optimize all the routine access to elements of the state; the one thing that becomes slightly trickier is when we need to iterate over all the clips in the entire state stack, as that'll need to consider both the stack of saved states (if any) and the separately-stored current state.

I'll put up a patch after some local testing.

Assignee: nobody → jfkthame
Blocks: 1822018
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/5b0011efcb58 Store current state directly in gfxContext, to avoid a separate allocation in the common case where Save/Restore is not used on the context. r=gfx-reviewers,lsalzman
Pushed by jkew@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/f34761df5a65 Store current state directly in gfxContext, to avoid a separate allocation in the common case where Save/Restore is not used on the context. r=gfx-reviewers,lsalzman
Status: NEW → RESOLVED
Closed: 2 years ago
Resolution: --- → FIXED
Target Milestone: --- → 113 Branch
Whiteboard: [sp3]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: