Skip to content

Commit 040b203

Browse files
authored
perf(desktop): make the Projects surface render-cheap (#6460)
Diagnostic profiling on a large community (101 issues, 258 PRs) showed Projects tab switches taking 2.5–3.6s, dominated by single React commits of 0.5–1.5s and per-render recomputation — fetch work was already off the main thread; the cost was building the UI. ### Measured: tab click → painted, per tab | tab | before | after | |---|---|---:| | projects | 3,608ms | 320–580ms | | repositories | 3,126–3,534ms | 310–410ms | | tasks | 395–1,101ms | ~115ms | | reviews | 322–2,603ms | ~96ms | | activity | 597–741ms | ~148ms | Single-commit ceiling dropped from 1,541ms to ≤200ms (growth steps 25–40ms). Fixes in profiled-cost order: - **Profile popover body mounts only while open.** `UserProfilePopover` carried seven query subscriptions plus interaction hooks per instance even when closed; grids mount hundreds (five per card in people stacks, one per row author) — measured **~40ms per card**, the dominant share of the 1.2s card-tab commits. The always-mounted shell is now just the Radix root + trigger; trigger markup, hover timing, and keyboard handling are unchanged, and hover/tooltip event continuity is preserved because the trigger never remounts. - **Incremental row mounting.** The first 12 cards / 30 rows render in the first commit; the rest stream in 36–60-per-frame low-priority transitions. Grouped lists trim across group boundaries via a pure, tested slicer; the mounted count survives in-place refetches. - **Activity feed**: was rebuilt unmemoized on every render, markdown-flattening every issue/PR/comment body in the community just to sort and keep 30 items (~360+ flattens per render on the measured community). Now memoized, and bodies stay raw until after the sort+slice — 30 flattens, once per data change. - **Contribution graph** (always-visible rail, so every tab paid for it): ~180 day cells each wrapped in a Radix tooltip with per-cell Intl date formatting per render. Now memoized, cells precomputed once per data change, native `title` tooltips. (The activity-bar segments keep their styled Radix tooltips — pinned by an existing spec.) - **Rows/cards memoized with identity-stable props**: per-row selection arrays were rebuilt per row per render (O(n²) — 258 PRs × 258-item arrays each render) and are now hoisted and shared; people arrays derive inside the memoized cards; the rail's stat walk over every issue/PR is memoized. - **`content-visibility: auto`** on cards and rows so offscreen entries skip layout and paint; **tab switches run in a React transition** so the click stays responsive while the new tree mounts. Remaining known cost (out of scope): cold-entry data readiness — the work-item and activity queries ship thousands of events to compute counts (2–4s on a large community; see the fan-lifecycle PR). The structural fix is a relay-side aggregate; tracked as follow-up. --------- Signed-off-by: Max Lampert <[email protected]>
1 parent f995325 commit 040b203

12 files changed

Lines changed: 1065 additions & 478 deletions

‎desktop/src/features/profile/ui/UserProfilePopover.tsx‎

Lines changed: 313 additions & 276 deletions
Large diffs are not rendered by default.

‎desktop/src/features/projects/ui/ProjectCards.tsx‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,9 @@ type ProjectItemProps = {
454454
onOpenTerminal: (project: Project) => Promise<void> | void;
455455
};
456456

457-
export function ProjectGridCard({
457+
// Memoized: these cards render in unbounded grids/lists; identity-stable
458+
// props from the caller keep re-renders scoped to genuinely changed cards.
459+
export const ProjectGridCard = React.memo(function ProjectGridCard({
458460
project,
459461
people,
460462
profiles,
@@ -469,7 +471,7 @@ export function ProjectGridCard({
469471
}: ProjectItemProps) {
470472
return (
471473
<Card
472-
className="group relative flex min-h-40 flex-col overflow-hidden border-border/60 bg-transparent shadow-none transition-colors duration-150 hover:bg-muted/20"
474+
className="group relative flex h-full min-h-40 flex-col overflow-hidden border-border/60 bg-transparent shadow-none transition-colors duration-150 hover:bg-muted/20"
473475
data-projects-grid-card
474476
data-testid={`project-card-${project.dtag}`}
475477
>
@@ -541,9 +543,9 @@ export function ProjectGridCard({
541543
</div>
542544
</Card>
543545
);
544-
}
546+
});
545547

546-
export function ProjectListRow({
548+
export const ProjectListRow = React.memo(function ProjectListRow({
547549
project,
548550
people,
549551
profiles,
@@ -617,7 +619,7 @@ export function ProjectListRow({
617619
}
618620
/>
619621
);
620-
}
622+
});
621623

622624
/** Compact, borderless repository row for the overview side rail. */
623625
export function ProjectRailRow({

‎desktop/src/features/projects/ui/ProjectsActivityFeed.tsx‎

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import * as React from "react";
2+
3+
import { useNow } from "@/shared/lib/useNow";
4+
15
import {
26
resolveUserLabel,
37
type UserProfileLookup,
@@ -181,7 +185,7 @@ function buildActivityItems({
181185
actorName: null,
182186
action: "created the repository",
183187
title: project.name,
184-
body: contentPreview(project.description),
188+
body: project.description,
185189
detail: null,
186190
target: { type: "project", project },
187191
});
@@ -228,7 +232,7 @@ function buildActivityItems({
228232
actorName: null,
229233
action: "opened a review in",
230234
title: pullRequest.title,
231-
body: contentPreview(pullRequest.content),
235+
body: pullRequest.content,
232236
detail: pullRequest.status,
233237
target,
234238
});
@@ -241,7 +245,7 @@ function buildActivityItems({
241245
actorName: null,
242246
action: "updated a review in",
243247
title: pullRequest.title,
244-
body: contentPreview(update.content),
248+
body: update.content,
245249
detail: update.commit?.slice(0, 7) ?? null,
246250
target,
247251
});
@@ -275,7 +279,7 @@ function buildActivityItems({
275279
? "requested review in"
276280
: "commented on a review in",
277281
title: pullRequest.title,
278-
body: contentPreview(comment.content),
282+
body: comment.content,
279283
detail:
280284
kind === "approval"
281285
? "Approved"
@@ -297,7 +301,7 @@ function buildActivityItems({
297301
actorName: null,
298302
action: "created a task in",
299303
title: issue.title,
300-
body: contentPreview(issue.content),
304+
body: issue.content,
301305
detail: issue.status,
302306
target,
303307
});
@@ -310,16 +314,26 @@ function buildActivityItems({
310314
actorName: null,
311315
action: "commented on a task in",
312316
title: issue.title,
313-
body: contentPreview(comment.content),
317+
body: comment.content,
314318
detail: null,
315319
target,
316320
});
317321
}
318322
}
319323

320-
return items
321-
.sort((left, right) => right.createdAt - left.createdAt)
322-
.slice(0, ACTIVITY_LIMIT);
324+
return (
325+
items
326+
.sort((left, right) => right.createdAt - left.createdAt)
327+
.slice(0, ACTIVITY_LIMIT)
328+
// Bodies are carried raw until here so the markdown flattening runs for
329+
// the rendered window only — every issue/PR/comment in the community
330+
// used to be flattened just to be sorted and discarded.
331+
.map((item) =>
332+
item.body === null
333+
? item
334+
: { ...item, body: contentPreview(item.body) },
335+
)
336+
);
323337
}
324338

325339
export function buildProjectsActivityAgentContextItems(
@@ -358,8 +372,8 @@ function startOfWeek(timestamp: number) {
358372
return Math.floor(date.getTime() / 1_000);
359373
}
360374

361-
function groupActivityItems(items: ProjectActivityItem[]) {
362-
const thisWeek = startOfWeek(Math.floor(Date.now() / 1_000));
375+
function groupActivityItems(items: ProjectActivityItem[], nowMs: number) {
376+
const thisWeek = startOfWeek(Math.floor(nowMs / 1_000));
363377
const lastWeek = thisWeek - WEEK_SECONDS;
364378
const groups: ProjectActivityGroup[] = [
365379
{ key: "this-week", label: "This week", items: [] },
@@ -596,8 +610,21 @@ function ActivityCard({
596610

597611
/** Mixed GitHub-style workspace activity shown beneath the overview callouts. */
598612
export function ProjectsActivityFeed(props: ProjectsActivityFeedProps) {
599-
const items = buildActivityItems(props);
600-
const groups = groupActivityItems(items);
613+
const { issues, projects, pullRequests, snapshots } = props;
614+
// Memoized: this feed re-renders with every parent state change (profiles
615+
// landing, selection, hover), and an unmemoized rebuild re-flattened and
616+
// re-sorted the whole community's activity each time.
617+
const items = React.useMemo(
618+
() => buildActivityItems({ issues, projects, pullRequests, snapshots }),
619+
[issues, projects, pullRequests, snapshots],
620+
);
621+
// Week buckets are clock-derived; ticked so the memo cannot freeze "This
622+
// week" across a week boundary. Coarse cadence — the boundary moves weekly.
623+
const now = useNow(600_000);
624+
const groups = React.useMemo(
625+
() => groupActivityItems(items, now),
626+
[items, now],
627+
);
601628
const rangeItems = groups.flatMap((group) =>
602629
group.items.flatMap((item) => {
603630
const selectionItem = activitySelectionItem(item);

‎desktop/src/features/projects/ui/ProjectsIssuesList.tsx‎

Lines changed: 79 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Eye, FolderKanban } from "lucide-react";
2+
import * as React from "react";
23

34
import type {
45
Project,
@@ -13,6 +14,11 @@ import {
1314
resolveUserLabel,
1415
type UserProfileLookup,
1516
} from "@/features/profile/lib/identity";
17+
import {
18+
countGroupedRows,
19+
sliceGroupedRows,
20+
useIncrementalMount,
21+
} from "@/shared/hooks/useIncrementalMount";
1622
import { cn } from "@/shared/lib/cn";
1723
import { BuzzLoadingState } from "@/shared/ui/BuzzLoadingState";
1824
import { Card } from "@/shared/ui/card";
@@ -53,14 +59,20 @@ function nextStepLabel(status: ProjectIssue["status"]) {
5359
return "Open task";
5460
}
5561

56-
function IssueGridCard({
62+
const IssueGridCard = React.memo(function IssueGridCard({
5763
issue,
5864
onOpen,
5965
project,
66+
repository,
6067
}: {
6168
issue: ProjectIssue;
62-
onOpen: (project: Project, issue: ProjectIssue) => void;
69+
onOpen: (
70+
project: Project,
71+
repository: Repository,
72+
issue: ProjectIssue,
73+
) => void;
6374
project: Project;
75+
repository: Repository;
6476
}) {
6577
return (
6678
<Card
@@ -69,7 +81,7 @@ function IssueGridCard({
6981
>
7082
<button
7183
className="absolute inset-0"
72-
onClick={() => onOpen(project, issue)}
84+
onClick={() => onOpen(project, repository, issue)}
7385
type="button"
7486
>
7587
<span className="sr-only">View task {issue.title}</span>
@@ -97,7 +109,7 @@ function IssueGridCard({
97109
</div>
98110
</Card>
99111
);
100-
}
112+
});
101113

102114
function issueSelectionItem(
103115
project: Project,
@@ -113,7 +125,10 @@ function issueSelectionItem(
113125
});
114126
}
115127

116-
function IssueListRow({
128+
// Memoized: these rows render in unbounded lists, and any Projects-view
129+
// state change used to re-render every row. Props are kept identity-stable
130+
// by the list (memoized groups/selection arrays, stable onOpen).
131+
const IssueListRow = React.memo(function IssueListRow({
117132
issue,
118133
onOpen,
119134
profiles,
@@ -122,7 +137,11 @@ function IssueListRow({
122137
repository,
123138
}: {
124139
issue: ProjectIssue;
125-
onOpen: (project: Project, issue: ProjectIssue) => void;
140+
onOpen: (
141+
project: Project,
142+
repository: Repository,
143+
issue: ProjectIssue,
144+
) => void;
126145
profiles?: UserProfileLookup;
127146
project: Project;
128147
rangeItems: ReturnType<typeof issueSelectionItem>[];
@@ -137,7 +156,7 @@ function IssueListRow({
137156
dateSeconds={issue.updatedAt}
138157
dateTestId="projects-row-date"
139158
icon={null}
140-
onClick={() => onOpen(project, issue)}
159+
onClick={() => onOpen(project, repository, issue)}
141160
peopleSlot={
142161
<ProjectAuthorIdentity
143162
label={authorLabel}
@@ -157,7 +176,7 @@ function IssueListRow({
157176
titleIcon={<ProjectEventTypeIcon className="h-3.5 w-3.5" kind="issue" />}
158177
trailing={
159178
<ProjectListRowMenu label={`More options for ${issue.title}`}>
160-
<DropdownMenuItem onSelect={() => onOpen(project, issue)}>
179+
<DropdownMenuItem onSelect={() => onOpen(project, repository, issue)}>
161180
<Eye className="h-4 w-4" />
162181
{nextStepLabel(issue.status)}
163182
</DropdownMenuItem>
@@ -170,7 +189,7 @@ function IssueListRow({
170189
}
171190
/>
172191
);
173-
}
192+
});
174193

175194
export function ProjectsIssuesList({
176195
embedded,
@@ -185,6 +204,40 @@ export function ProjectsIssuesList({
185204
profiles,
186205
viewMode,
187206
}: ProjectsIssuesListProps) {
207+
// Grouping and per-group selection arrays are identity-stable across
208+
// re-renders so the memoized rows only re-render when their data changes.
209+
const allGroups = React.useMemo(
210+
() =>
211+
groupProjectWorkItemsByProject(issues).map((group) => ({
212+
...group,
213+
selectionItems: group.rows.map((row) =>
214+
issueSelectionItem(row.project, row.repository, row.issue),
215+
),
216+
})),
217+
[issues],
218+
);
219+
// Mount rows progressively: a one-shot mount of hundreds of rows blocked
220+
// the main thread for over a second on tab entry.
221+
// Each layout's counter grows only while that layout is active: otherwise
222+
// a layout switch would find the other counter already grown and mount the
223+
// whole collection in one commit.
224+
const mountedRowCount = useIncrementalMount(
225+
countGroupedRows(allGroups),
226+
30,
227+
60,
228+
viewMode !== "grid",
229+
);
230+
const mountedGridCount = useIncrementalMount(
231+
issues.length,
232+
30,
233+
60,
234+
viewMode === "grid",
235+
);
236+
const groups = React.useMemo(
237+
() => sliceGroupedRows(allGroups, mountedRowCount),
238+
[allGroups, mountedRowCount],
239+
);
240+
188241
if (isLoading) {
189242
return <BuzzLoadingState label="Loading tasks" />;
190243
}
@@ -224,31 +277,28 @@ export function ProjectsIssuesList({
224277
<div className="space-y-3">
225278
{loadNotice}
226279
<div className="grid gap-3 md:grid-cols-2 xl:grid-cols-3">
227-
{issues.map(({ project, issue, repository }) => (
228-
<IssueGridCard
229-
issue={issue}
230-
key={`${repository.id}:${issue.id}`}
231-
onOpen={(selectedProject, selectedIssue) =>
232-
onOpen(selectedProject, repository, selectedIssue)
233-
}
234-
project={project}
235-
/>
236-
))}
280+
{issues
281+
.slice(0, mountedGridCount)
282+
.map(({ project, issue, repository }) => (
283+
<IssueGridCard
284+
issue={issue}
285+
key={`${repository.id}:${issue.id}`}
286+
onOpen={onOpen}
287+
project={project}
288+
repository={repository}
289+
/>
290+
))}
237291
</div>
238292
</div>
239293
);
240294
}
241295

242-
const groups = groupProjectWorkItemsByProject(issues);
243-
244296
return (
245297
<div className="space-y-3">
246298
{loadNotice}
247299
<div data-testid="projects-list-container">
248300
{groups.map((group) => {
249-
const groupSelectionItems = group.rows.map((row) =>
250-
issueSelectionItem(row.project, row.repository, row.issue),
251-
);
301+
const groupSelectionItems = group.selectionItems;
252302
return (
253303
<ProjectSelectableGroup
254304
count={group.rows.length}
@@ -264,12 +314,13 @@ export function ProjectsIssuesList({
264314
>
265315
<ul>
266316
{group.rows.map(({ project, issue, repository }) => (
267-
<li key={`${repository.id}:${issue.id}`}>
317+
<li
318+
className="[contain-intrinsic-size:auto_3.5rem] [content-visibility:auto]"
319+
key={`${repository.id}:${issue.id}`}
320+
>
268321
<IssueListRow
269322
issue={issue}
270-
onOpen={(selectedProject, selectedIssue) =>
271-
onOpen(selectedProject, repository, selectedIssue)
272-
}
323+
onOpen={onOpen}
273324
profiles={profiles}
274325
project={project}
275326
rangeItems={groupSelectionItems}

0 commit comments

Comments
 (0)