Skip to content

perf(web): virtualize the Web Apps sidebar list again - #41397

Merged
lyzno1 merged 4 commits into
langgenius:mainfrom
BenjaminX:perf/virtualize-web-apps-sidebar
Aug 27, 2026
Merged

lyzno1 merged 4 commits into
langgenius:mainfrom
BenjaminX:perf/virtualize-web-apps-sidebar

Conversation

@BenjaminX

@BenjaminX BenjaminX commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #41396

Summary

web/app/components/main-nav/components/web-apps-section.tsx rendered the installed-app list through useVirtualizer with a virtualizationThreshold of 50 rows. #39739 ("chore: paginate installed apps") moved the section to cursor pagination and dropped the virtualizer along the way, so every loaded page now stays in the DOM. The section lives in the main nav, so those rows survive route changes and are repainted on every navigation.

On a workspace with 427 installed apps, a Safari Web Inspector timeline recorded while clicking through the top-level nav entries spends 1067.7ms of 3.06s in composite (35%) across 12,112 paint records, and renders 23 frames — about 7.5 fps. All script categories together account for only ~830ms, and navigation RSC payloads are 340 B – 3.2 KB, so the cost is in painting and compositing rather than in JavaScript or loading. Controlled A/B/A measurements on that deployment put CSS mask-image icons as the largest single paint factor (+42% fps when masks are disabled, with box-shadow, border-radius, filter, transition and content-visibility all within noise), and every row here carries one. The un-virtualized rows multiply exactly that cost. Full numbers are in the issue.

This change restores the row model and virtualizer that existed before #39739, on top of the current infinite-query data source:

  • The pinned/unpinned Divider is folded back into a WebAppListRow union, so the separator is a virtual row with its own estimateSize rather than something rendered inline between rows.
  • The list is now always virtualized. The old threshold is not restored, so there is a single render path instead of a branch between flow layout and virtual rows — one fewer branch to lose next time. Worth noting the threshold protected the common case rather than the expensive one: pagination loads 20 rows at a time, so a list only crossed 50 after the user scrolled the sidebar. The reason to drop it is the simpler single path, not the row count.
  • InfiniteScrollSentinel is untouched. The virtual container is sized to the full list, so the sentinel still sits below it and preloads exactly as before.

Which icon, precisely

Since it matters for any follow-up: the app icon on each row is an <em-emoji> or an <img> rendered by AppIcon, not a mask icon. The mask-image icon on every row is the ItemOperation trigger, i-ri-more-fill, which is mounted per row and kept at opacity-0 until the row is hovered. Each un-virtualized row therefore paints a mask icon that is never visible. This PR cuts the row count; not painting a permanently invisible icon per row is a separate improvement and is not attempted here.

On the suggestion of moving these icons from mask-image to background-image: the generated stylesheet already splits the two, 426 monochrome icons on mask-image and 16 multi-color icons on background-image. The mask-image path is what lets monochrome icons inherit currentColor — i-ri-more-fill is coloured through text-* tokens here — so moving them to background-image would lose theming. The alternative that keeps theming is inline <svg fill="currentColor">, which runs against web/CLAUDE.md's instruction not to add generated React icons under app/components/base/icons/src/. I also have not measured background-image to be cheaper to paint than mask-image, so I would not want to assume that without a benchmark. Happy to open a separate issue for it.

Screenshots

Before After
N/A N/A

This change is visually identical — it only affects how many rows are mounted and painted. I have not attached a capture of the reporting workspace because the sidebar shows internal application names. The measurements above and in the issue stand in for a visual diff.

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods

Notes on the checklist: this is a frontend-only change, so the backend commands do not apply. Two cases were added to web/app/components/main-nav/__tests__/index.spec.tsx, one covering that the list is virtualized and one pinning the separator row's own measurement, and both were verified to fail without the component change. The file needs vi.mock('@tanstack/react-virtual') — matching the four existing specs that do the same — because the real virtualizer measures a zero-height scroll element under jsdom and renders no rows. app/components/main-nav is green at 5 files / 100 tests. Four spec files unrelated to this change are already failing on main (for example features/agent-v2/agent-detail/access/components/__tests__/access-surface-cards.spec.tsx); I confirmed they fail identically with this change stashed.

From Claude Code

langgenius#39739 introduced cursor pagination for installed apps and dropped the
`useVirtualizer` rows that guarded this list, so every loaded page now stays
in the DOM. The section lives in the main nav, so those rows persist across
route changes and are repainted on every navigation.

On a workspace with 427 installed apps this is very visible: a Safari
timeline of clicking through the top-level menus spends 1067ms of 3.06s in
compositing (35%) across 12,112 paint records and renders 23 frames, i.e.
7.5fps. Controlled A/B/A runs on that page (zero baseline drift) put the
mask-image icons each row carries as the single largest paint factor at
+42% fps when removed, which is what the extra rows multiply.

Restore the row model and virtualizer from before langgenius#39739, keeping the
existing threshold so short lists stay in plain flow layout. The infinite
scroll sentinel is unchanged: the virtual container is sized to the full
list, so the sentinel still sits below it and preloads as before.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Aug 27, 2026
@github-actions github-actions Bot added the web This relates to changes on the web. label Aug 27, 2026
Follow-up to review feedback: drop `virtualizationThreshold` so the section
has a single render path instead of branching between flow layout and
virtual rows. This removes the branch that langgenius#39739 had to reason about, which
is the branch that was lost in the first place.

Note that the threshold protected the common case rather than the expensive
one: cursor pagination loads 20 rows at a time, so a list only crossed the
old threshold of 50 after the user scrolled the sidebar. The reason to drop
it is the simpler single path, not the row count.

Tests now cover always-on virtualization and pin the separator row's own
measurement, which is the part of the row model that is easy to get wrong
when the list is virtualized.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@BenjaminX

Copy link
Copy Markdown
Contributor Author

Thanks for the analysis — pushed 204b096871 in response. Point by point:

Separator row. Already handled in the first commit, in the form you suggested: WebAppListRow is a union of 'app' and 'separator' entries and estimateSize returns appNavSeparatorHeight for the latter, rather than the inline index === pinnedAppsCount - 1 that this PR removes. I've added a test that pins the measurement (four 32px rows plus one 17px separator = 145px), since it is the easy part to get wrong.

Virtualization threshold. Dropped, so there is now a single render path. One correction to the reasoning though: loading 20 at a time means a list only crossed the old threshold of 50 after the user scrolled the sidebar, so the threshold was protecting the common case rather than the expensive one. The good reason to drop it is the simpler single path — one fewer branch to lose next time — which is what I've gone with.

mask-image → background-image. I don't think this works as stated. The generated stylesheet already splits the two: 426 monochrome icons on mask-image, 16 multi-color ones on background-image. The mask path is what lets monochrome icons inherit currentColor, and the icon in question here is coloured through text-* tokens, so moving it to background-image would lose theming. Inline <svg fill="currentColor"> would keep theming but runs against web/CLAUDE.md's instruction not to add generated React icons under app/components/base/icons/src/. I also haven't measured background-image to actually be cheaper to paint, so I'd rather not assume it. Happy to open a separate issue if you want it explored.

While checking that, I found I'd been imprecise in the description and have corrected it in both the issue and this PR: the per-row mask-image icon is not the app icon (that's <em-emoji>/<img> via AppIcon) — it's the ItemOperation trigger i-ri-more-fill, mounted for every row and held at opacity-0 until hover. So each un-virtualized row paints an icon that is never visible. Cutting the row count addresses that here; not painting an invisible icon per row is a separate improvement I haven't attempted.

content-visibility: auto. Agreed, and your framing is better than mine — it skips rendering while keeping the node and its layout box, so it was never going to substitute for not mounting the rows. That also resolves a caveat I had, since I couldn't rule out that the null result was just Safari version support.

From Claude Code

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Aug 27, 2026
@lyzno1

lyzno1 commented Aug 27, 2026

Copy link
Copy Markdown
Member

Thanks!

@lyzno1
lyzno1 added this pull request to the merge queue Aug 27, 2026
Merged via the queue into langgenius:main with commit 2a554ab Aug 27, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files. web This relates to changes on the web.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Web Apps sidebar keeps every loaded row in the DOM since #39739, degrading navigation on large workspaces

2 participants