progress-bar-animation icon indicating copy to clipboard operation
progress-bar-animation copied to clipboard

Perf Audit

Open paulirish opened this issue 9 years ago • 11 comments

Going to dump my notes in here an edit as I go.

Starting with the master branch as that seems preferred for ergonomics.

  • Test URL: http://rawgit.com/kdzwinel/progress-bar-animation/master/index.html
  • Setup: MacBook Air (to start with)

image

Looks like a case of heavy rasterization. SVG gets this a lot.

Let's see what we can do!

paulirish avatar Apr 10 '16 23:04 paulirish

I applied some absolute positioning to visually distinguish things with paint flashing on.

image

Okay so the SVG is rasterizing each frame. The DIV only rasterizes at the toggle.

Still I think the DIV shouldn't need to rasterize much at all. Curious if we can get rid of that.

(That said, the SVG rasterization is whats really important)

paulirish avatar Apr 10 '16 23:04 paulirish

Nuking the raster costs on the avatar div

will-change: transform on both the div.avatar and the .avatar-box:before take care of the rasterization flashes: Woo!

image

Before and After

We're looking at the exact same flip here. That raster cost in the middle is gone.

image

paulirish avatar Apr 10 '16 23:04 paulirish

raster costs of the SVG

Setting display: none !important; on the avatar, now that it's sorted, so we can look at the SVG all alone.

Yup. It's just hitting a lot of rasterization costs on every frame.

image

Damn. using the animation editor is a nice way to diagnose the animation itself. Pause and scrubber dragging totally kick ass:

image


Now, re-reading the project readme. The technique explored in "reverse" is my best guess for what's going have the most promise. Going to move over there.

paulirish avatar Apr 10 '16 23:04 paulirish

Splitting apart the SVG layers

Using the reverse branch, I again see that raster costs of the SVG during its path animation are the problem. I was curious if we could reduce that cost by getting rid of some extra stuff. So I tried splitting the white circle in the middle of the SVG out to a static SVG that doesn't change:

image

Comparing it to before, the rasterization costs seem much smaller. image

NEVERMIND. Put back the white circle and the raster costs are still down. Maybe it was something else I did.

paulirish avatar Apr 10 '16 23:04 paulirish

Oh reverse is just much less rasterization than master was. That's all. :) Nice job.

paulirish avatar Apr 10 '16 23:04 paulirish

reverse on Android

Things are looking fine on desktop, even with CPU throttling, so over to remote debugging my nexus 5X

image

Raster time is bigger here. ~12ms per frame. With that time, it's possible we could still hit 60fps, but it'd be tight.

Unfortunately, the GPU is the bottleneck here. Bigtime.

Curious about Ganesh in this case....

paulirish avatar Apr 11 '16 00:04 paulirish

Ganesh & GPU

Ganesh is on.. I tried turning it off, but there's not a sigificant difference either way.

GPU is the bottleneck for sure.

Tracing to see if that provides any more details:

image

No insights here. Just taking time flushing all the work to the GPU each frame.

paulirish avatar Apr 11 '16 00:04 paulirish

I've exhausted my own techniques on this one.

cc @progers @fregu In case you guys are interested in a a well-optimized SVG animation that just isn't good enough. See the readme at https://github.com/kdzwinel/progress-bar-animation for details.

Repro:

  1. Open http://rawgit.com/kdzwinel/progress-bar-animation/reverse/index.html on mobile
  2. See that raster + GPU costs are a bit costly. Main thread compositing is also reliably expensive.
  3. Try to reduce those costs.

paulirish avatar Apr 11 '16 00:04 paulirish

@paulirish this is very problematic with material design spinners when used in an application transition state. Can we expect any improvements here in the medium term?

nathanmarks avatar Apr 22 '16 17:04 nathanmarks

@paulirish From what's public, Ganesh appears not to work at all when some SVG is involved:

Note that GPU rasterization can get vetoed based on the content itself. For example, if page contains many SVGs with non-convex paths (common for SVG icons), GPU rasterization may get disabled for that page load.

tigt avatar Nov 02 '16 13:11 tigt

It's not a complete veto for svg. The heuristic is based on the absolute number of non-convex paths.

There are two ongoing projects in progress now that will likely remove this heuristic/veto soon.

progers avatar Nov 02 '16 21:11 progers