adobe-photoshop / spaces-design

Adobe Photoshop Design Space
http://adobe-photoshop.github.io/
Other
848 stars 81 forks source link

Document load time: descriptor and lazy properties optimization #3771

Open shaoshing opened 8 years ago

shaoshing commented 8 years ago

This PR is a work in progress Please let me know:


This PR introduces the following optimization to improve the document load time performance.

1. Load layer bounds lazily

Instead of loading bounds for all layers during startup, which can be slow for large documents, we will only load bounds that are necessary to render the TransformPanel, which are bounds of the selected layers and their children (for art board, child bounds are not required). The best case for this optimization is when the document has 0 selected layer, the worse case is when layers are all selected (which I think is less likely to happen and we can prevent such performance drawback). However, I guess the most typical case is that the document has less than 10 selected layers/groups during startup.

Time reduced: 300ms - 450ms

2. Load layer bounds selectively

When fetching bounds at startup, we ask PS to return all bounds (artboard, bounds, boundingBox, boundsNoMask, boundsNoEffects, pathBounds), which causes PS to spend more time on gathering/generating/sending the result. This is also unnecessary in DS as each layer is only reading one type of bounds, depends on its layer type (https://github.com/adobe-photoshop/spaces-design/blob/master/src/js/models/bounds.js#L153). This optimization allows DS to fetch the desired bounds for each layer during startup.

Time reduced: 60ms - 120ms

3. faster background initialization

Properties that are initialized during startup should be skipped in the background initialization. These properties are

Time reduced: the average time of initializing 50 layers is 28ms now, compare to 132ms before. For vermilion document, . This allows us, for example, increase the number of layers initialized each time (e.g. the average time for 150 layers is 87ms), and can result in a much faster background initialization.

4. avoid empty batchPlay

We were executing some empty batchPlay descriptors when loading a document with zero selected layer. By avoiding these commands, we can save around 70ms for large documents like vermilion.

5. Type initialization (pending)

We are initializing all text layers in type.initFontList (https://github.com/adobe-photoshop/spaces-design/blob/shao/lazy-bounds/src/js/actions/type.js#L760), which feels like a duplicate with the layers.initializeLayersBackground. This takes about 1600ms to complete for vermilion document.

Result

Before (ms) After (ms) Diff (ms)
new doc (deselect all) 663 674 +11
new doc (select all) 741 756 +15
vermilion (collapse/deselect all AB) 1435 891 -544
vermilion (collapse all AB, select last AB) 1695 1183 -512
vermilion (expand last AB, select "480px - Mobile") 2461 1904 -557
vermilion (expand last AB, and select all layers of the AB) 3146 2788 -358
large vermilion (3455 layers, collapse/deselect all AB) 3702 1876 -1826
open file: vermilion 5111 4026 -1085
background initilization (50 layers) 132 28 -104

Todos

iwehrman commented 8 years ago

Can you describe at a high level about how the SuperselectOverlay copes with the lack of bounds on startup? Previously, I avoided similar optimizations because it wasn't obvious what to do there.