perf(media-releases): stop rendering 73 off-screen cards' images and layout
Per-widget attribution of the dashboard found one widget responsible for 44% of the
board's DOM: mediaReleases at 2,951 nodes and 8,387 fibers, including 1,935 Mantine
Box components, against a board total of 9,293 nodes.
The cause is that it maps over every release the integrations return, with no cap.
Measured on a real board: the tile is 539 px tall and its content is 7,206 px, so of
80 rendered cards only 7 are visible. The other 73 cost DOM, fibers, and - most
expensively - a poster and a CSS backdrop image each, all fetched and decoded for
pixels nobody can see. Decoded bitmaps are far larger in memory than their files.
Fixed with content-visibility: auto plus contain-intrinsic-size on each card, so the
browser skips layout, paint, raster and background-image fetch for off-screen cards,
and loading="lazy" on the poster. Nothing leaves the DOM, so scrolling and in-page
search are unchanged, and the intrinsic size keeps the scrollbar from jumping.
Measured over three repeats per side on identical restored data:
image requests 135, 135, 135 -> 55, 55, 56 (-59%, deterministic)
image bytes 12.27 MiB -> 8.41 MiB (-31%)
layout objects 8346, 7815, 7815 -> 5117, 4696, 4636 (-41%)
Two things this does NOT show, stated because a single run suggested otherwise:
- JS heap did not clearly improve. Across four runs it was 46-88 MiB before against
74-86 MiB after; the before spread is 2x, so no claim either way. This is expected:
decoded image memory lives outside JSHeapUsedSize, so the actual saving from 81
fewer image fetches is invisible to that metric.
- Task duration and time-to-settled overlap between arms and support no conclusion.
Adds the tools this needed: measure-widget-cost.mts (per-widget DOM nodes, fibers and
heaviest components), measure-board-paint.mts (image requests, bytes, style/layout/task
time, layout objects), measure-widget-overdraw.mjs (rendered versus visible rows).
This commit is contained in:
4 files changed
+321
-1
No files matched your search
@@ -71,6 +71,19 @@ const Item = ({ item, options }: ItemProps) => {
|
||||
rel="noopener noreferrer"
|
||||
pos="relative"
|
||||
p={options.layout === "poster" ? 0 : 4}
|
||||
style={{
|
||||
// This widget maps over every release the integrations return. Measured on a real board:
|
||||
// 80 cards rendered into a 539 px tile whose content is 7,206 px tall, so 73 of them are
|
||||
// scrolled out of view — along with their backdrop and poster images, which the browser
|
||||
// otherwise fetches, decodes and rasterises for pixels nobody can see.
|
||||
//
|
||||
// content-visibility lets the browser skip layout, paint and raster for a card that is
|
||||
// off-screen, and contain-intrinsic-size gives it a placeholder height so the scrollbar
|
||||
// does not jump as cards enter and leave. Nothing is removed from the DOM, so scrolling
|
||||
// and in-page search behave exactly as before.
|
||||
contentVisibility: "auto",
|
||||
containIntrinsicSize: "auto 88px",
|
||||
}}
|
||||
>
|
||||
{options.layout === "backdrop" && (
|
||||
<Box
|
||||
@@ -91,7 +104,11 @@ const Item = ({ item, options }: ItemProps) => {
|
||||
)}
|
||||
<Group justify="space-between" h="100%" wrap="nowrap">
|
||||
<Group align="start" wrap="nowrap" style={{ zIndex: 0 }}>
|
||||
{options.layout === "poster" && <Image w={60} src={item.imageUrls.poster} alt={item.title} />}
|
||||
{options.layout === "poster" && (
|
||||
// Only a handful of the rendered cards are on screen; loading the rest's posters
|
||||
// eagerly costs a request and a decoded bitmap each for no visible benefit.
|
||||
<Image w={60} src={item.imageUrls.poster} alt={item.title} loading="lazy" />
|
||||
)}
|
||||
<Stack gap={4}>
|
||||
<Stack gap={0}>
|
||||
<Text size="sm" fw="bold" lineClamp={2}>
|
||||
|
||||
Reference in new issue
Block a user