Closed Bug 1642629 Opened 1 year ago Closed 1 year ago

Various frame building optimizations

Categories

(Core :: Graphics: WebRender, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED

People

(Reporter: nical, Assigned: nical)

References

(Blocks 1 open bug)

Details

Attachments

(18 files)

47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
47 bytes, text/x-phabricator-request
Details | Review
No description provided.
Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/055e358cab6c
Reduce the amount of vector reallocation when adding primitives to batches. r=gw

These vectors are rebuilt once per frame. we can't recycle them because they are sent to the renderer. On a 4k screen for most sites the element counts are low enough that we can get away with preallocation from a pessimistic estimate, but high enough that reallocation happens a few times per frame and takes a small but visible portion of the profile.

Keywords: leave-open

Tested this on a few pages and it lets us avoid allocating per-item rects for roughly a quarter to a third of the batches. For batches that end up allocating per item rects we get to allocate fewer of them. It also further reduces the amount of times we need to test all item rects against intersections.

Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/3d4463013cc1
preallocate a few vectors in CompositeState. r=gw
https://hg.mozilla.org/integration/autoland/rev/d90ad820b1f0
Avoid iterating over all batch item rects in some cases. r=kvark

An alternative patch to take only if we don't land https://phabricator.services.mozilla.com/D79545

The main observations here are:

  • In the vast majority of times we find a compatible bacth or intersect an incompatible one within 3 iterations when looking for batch candidates.
  • In addition, most of the time we don't need to iterate per-item rects thanks to a fast path kleveraging per-batch bounding rects, making it reasonably cheap to iterate over more batches.

This gives us room to allow ourselves to visit a lot more batches without a large impact on CPU time (under the assumption that removing a handful of draw calls will more than make up for the extra iterations).

Depends on D79479

Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/853d601fe2e1
Only track per-item rects in batches if a per-batch approximation isn't good enough. r=kvark

This vector is usually small, but on some pages it can be fairly large (500+ in https://forum.xda-developers.com/redmi-note-3/development for example).

Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/149ca53d3549
Remove the lookback limit for alpha batches. r=kvark
Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/217914372d03
Recycle the surface info vector in frame building. r=gw
Flags: needinfo?(nical.bugzilla)

This change just restructures the recycling added in previouscommits.

Attachment #9157618 - Attachment description: Bug 1642629 - Recycle shared clips allocation in picture.rs. r=gw → Bug 1642629 - Recycle shared clips allocation in picture.rs. r=kvark

This patch a simple utility to help with pre-allocating vectors that we can't recycle and use it with the primitive headers.

Depends on D80193

Vector reallocations in CompositeState::push_surface are taking about 2% of total frame building time before this patch. There was an effort at preallocating some with constant values but I suspect these constants haven't been updated along with picture cachign heuristics.

Depends on D80194

Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/33d6d6b9097d
Recycle the surface info vector in frame building. r=gw
https://hg.mozilla.org/integration/autoland/rev/683b75cdd3c4
Recycle a couple of vectors in PictureUpdateState. r=gw
https://hg.mozilla.org/integration/autoland/rev/88dd02d36e0d
Recycle dirty_region_stack in FrameBuilder. r=gw
https://hg.mozilla.org/integration/autoland/rev/073fe13cd98b
Regroup recycled data structures into scratch buffers. r=gw
https://hg.mozilla.org/integration/autoland/rev/a076f17ed2da
Recycle shared clips allocation in picture.rs. r=kvark
https://hg.mozilla.org/integration/autoland/rev/2195069a75c9
Reserve items in SegmentBuilder before simple loops. r=kvark
https://hg.mozilla.org/integration/autoland/rev/325a298e5e11
Recycle FrameVisibilityState's clip_chain_stack and surface_stack. r=kvark

It would be wasteful to preallocate all batch builders because the majority of them have only a single batch, while typically only one will will have many batches. Thankfully we can acurately guess which pictures will produce many batches by checking whether they have more than one cluster.

Flags: needinfo?(nical.bugzilla)
Pushed by nsilva@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/93505e39bf57
Recycle the surface info vector in frame building. r=gw
https://hg.mozilla.org/integration/autoland/rev/9c4d5596e220
Recycle a couple of vectors in PictureUpdateState. r=gw
https://hg.mozilla.org/integration/autoland/rev/6203b2994812
Recycle dirty_region_stack in FrameBuilder. r=gw
https://hg.mozilla.org/integration/autoland/rev/dc3d4d706d11
Regroup recycled data structures into scratch buffers. r=gw
https://hg.mozilla.org/integration/autoland/rev/d7ddc0cdffa2
Recycle shared clips allocation in picture.rs. r=kvark
https://hg.mozilla.org/integration/autoland/rev/7cbc9b5f00f1
Reserve items in SegmentBuilder before simple loops. r=kvark
https://hg.mozilla.org/integration/autoland/rev/f26158a3994c
Recycle FrameVisibilityState's clip_chain_stack and surface_stack. r=kvark
https://hg.mozilla.org/integration/autoland/rev/ac1dec27b771
Preallocate the primitive headers vector. r=kvark
https://hg.mozilla.org/integration/autoland/rev/1e531a6c2590
Preallocate CompositeStateDescriptor vectors. r=kvark
https://hg.mozilla.org/integration/autoland/rev/a16036b4b36c
Reserve GpuBlockData vector before pushing in a loop. r=kvark
https://hg.mozilla.org/integration/autoland/rev/17684b39b0ba
Preallocate gpu cache texture vectors. r=gw
https://hg.mozilla.org/integration/autoland/rev/e891a846e7f3
Reserve sorted polygon list before pushing know number of split planes into it. r=gw
https://hg.mozilla.org/integration/autoland/rev/45ef8e463b6e
Preallocate the batches and batch rects vectors. r=gw
Status: NEW → RESOLVED
Closed: 1 year ago
Keywords: leave-open
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.