if there are any scenarios that you think will not work with the optimization?
any suggestion/question about the implementation.
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.
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.
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, theworse 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 themost 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 thelayers.initializeLayersBackground
. This takes about 1600ms to complete for vermilion document.Result
Todos
_getLayerByRef
with_getLayerDescriptors
NaN
warning from text input