engine icon indicating copy to clipboard operation
engine copied to clipboard

[web] specialize transform and offset layers

Open yjbanov opened this issue 2 years ago • 2 comments

Specializes the OffsetEngineLayer and TransformEngineLayer in CanvasKit mode. Random usage of the Gallery app shows that ~97% of all transforms are covered by identity and translation specializations.

Two specializations are introduced:

  • Identity: for the case where the transform is a noop no extra work is required in either preroll or paint. In this case, the layer simply prerolls and paints its children. No matrices are created, and in the paint phase save/restore are eliminated.
  • Translation: for the case when the transform is a translation along x and/or y, SkCanvas.translate is used, which only passes 2 on-stack floats (8 bytes) instead of a 4x4 on-heap matrix (64 bytes).

BEFORE: OffsetEngineLayer has been delegating to TransformEngineLayer, which in turn treated every transform as a general transform needing a full 4x4 matrix. We use float32 matrices, so each matrix needs 64 bytes to store transformation data. Copying that data from Dart to C++ has been showing up in profiles reported by a Google customer.

AFTER: the specializations cover 100% of OffsetEngineLayer needs. For TransformEngineLayer, clicking and scrolling randomly around the Gallery app, ~26% is covered by identity, and ~31% is covered by translation. Only ~42% need the full 4x4 matrix. Additionally, ~93% of all transforms are expressed using OffsetEngineLayer. So the two specializations cover ~97% of all transforms in the app. For more numbers, see this spreadsheet.

yjbanov avatar Jul 08 '22 22:07 yjbanov

Gold has detected about 1 new digest(s) on patchset 2. View them at https://flutter-engine-gold.skia.org/cl/github/34556

skia-gold avatar Aug 05 '22 21:08 skia-gold

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

flutter-dashboard[bot] avatar Aug 28 '22 17:08 flutter-dashboard[bot]

Will close for now. Will create a new one after I clean it up.

yjbanov avatar Nov 16 '22 01:11 yjbanov