Skip to content

Re-render only what changed on each progress update - #151

Merged
anmolkapil merged 1 commit into
anmolkapil:mainfrom
Arpit-Khandelwal:perf/fewer-rerenders
Oct 16, 2026
Merged

anmolkapil merged 1 commit into
anmolkapil:mainfrom
Arpit-Khandelwal:perf/fewer-rerenders

Conversation

@Arpit-Khandelwal

Copy link
Copy Markdown
Collaborator

Every progress update (about 5 a second per running download) re-rendered much more of the window than changed:

  • App subscribed to all of downloads and history, so each update re-rendered the title bar, status bar, dialogs and the whole screen under them.
  • useNetworkVisuals returned a new function on every render. That defeated DownloadRow's memo, despite the comment saying it's stable.
  • Each row's context menu got a new chosen array, so every row in the list re-rendered on every update (~38 components each).

Changes

  • A small CurrentScreen child of App selects only the shown download. App, TitleBar, StatusBar and the dialogs no longer re-render on progress.
  • useNetworkVisuals derives its colours from the set of known networks (a string key) and memoises the resolver, so it stays the same until a network or preference actually changes.
  • Each row and its context menu are memoised together (ListedDownload), and only selected rows receive the selection. The menu already uses chosen only when its row is selected (availableActions(selected ? chosen : [item])), so behaviour is unchanged.

No visual or behavioural change.

Measured (React commit counting via a DevTools hook plus CDP Performance.getMetrics, interleaved A/B runs on a loaded machine, so treat the CPU figures as approximate):

before after
List (2 running, 6 queued): component renders/s ~2,700 ~540 (−80%)
List: main-thread ms/s 38–50 22–34
Download screen (2 running): component renders/s ~1,900 ~650 (−63%)
Download screen: script ms/s 25–61 13–23

Lint and typecheck are clean. ui, downloadActions and selection pass, apart from selection.spec.ts:133, which fails on main too and is fixed by #150.

Separately, while measuring I found that the combine diagram's flowing dashes (stroke-dashoffset CSS animation) repaint every frame for as long as a download runs. With updates frozen they were most of the remaining renderer CPU (~13% vs ~3% with that animation off). I haven't touched it, since stepping the animation down makes the dashes visibly choppier and that's a design call, but I'm happy to explore options if you're interested.

App subscribed to every download and to history, so each progress push
re-rendered the title bar, status bar, dialogs and the whole screen under
them. useNetworkVisuals returned a new function on every render, which
defeated DownloadRow's memo, and each row's context menu got a new chosen
array, so every row in the list re-rendered on every push.

- Select only the shown download, in a CurrentScreen child of App.
- Key useNetworkVisuals on the set of known networks and memoize it.
- Memoize each list row together with its context menu, passing the
  selection only to rows that are selected.
@anmolkapil

Copy link
Copy Markdown
Owner

🙌🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants