perf(grid-pool): position slots with transform instead of top/left
The Web Inspector perf trace showed scroll-time was dominated by layout, not script or paint. Single layout records ran 750ms-1.5s each, triggered by scroll → animation-frame → slot position update. Each slot's `style="top: Npx; left: Mpx"` mutation invalidates its own layout box, and with 80 slots repositioned per scroll tick the cascade became the frame. `transform: translate(x, y)` on the same absolutely-positioned slot goes straight to paint/composite and skips layout entirely. Reported even under software compositing the GPU-layer cost is negligible compared to the layout work it eliminates. cc
This commit is contained in:
1 file changed
+11
-3
@@ -178,7 +178,7 @@
|
||||
{@const item = inRange ? (void dataVersion, getItem(albumIdx)) : null}
|
||||
<div
|
||||
class="grid-slot"
|
||||
style="top: {slotTopPx(slotIdx)}px; left: {slotLeftPx(slotIdx)}px; width: {cardWidth}px; display: {inRange ? 'block' : 'none'};"
|
||||
style="transform: translate({slotLeftPx(slotIdx)}px, {slotTopPx(slotIdx)}px); width: {cardWidth}px; display: {inRange ? 'block' : 'none'};"
|
||||
>
|
||||
{#if inRange}
|
||||
{#if item !== null}
|
||||
@@ -210,7 +210,15 @@
|
||||
|
||||
.grid-slot {
|
||||
position: absolute;
|
||||
/* No `will-change: transform` — under software compositing the
|
||||
extra GPU-layer hint costs more than it saves. */
|
||||
top: 0;
|
||||
left: 0;
|
||||
/* Positioning is done with `transform: translate(...)` inline (set
|
||||
by the script) instead of `top`/`left`. Reason: changing top/left
|
||||
on an absolutely-positioned element triggers layout, and with
|
||||
~80 slots all repositioned per scroll tick the layout cascade
|
||||
was ~1s/frame under software compositing — visible as the giant
|
||||
layout spikes on the perf trace. `transform` goes straight to
|
||||
paint/composite without invalidating layout, eliminating the
|
||||
cost regardless of HW or SW comp. */
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user