perf(desktop): virtualize unbounded lists and warm the emoji index (#1089)

Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
Co-authored-by: npub1mn7jgtj4w2pd0g0zeuhxsa6jy6p0rewxz4kujt98my82ahfmp72sxjexk7 <dcfd242e557282d7a1e2cf2e6877522682f1e5c6156dc92ca7d90eaedd3b0f95@sprout-oss.stage.blox.sqprod.co>
This commit is contained in:
Will Pfleger
2026-06-17 15:01:09 -04:00
committed by GitHub
parent 3bf2ac0047
commit a4fbebb397
17 changed files with 686 additions and 201 deletions

View File

@@ -42,7 +42,7 @@ export function AgentSessionTranscriptList({
role="log"
>
{items.map((item) => (
<div className="mt-4 first:mt-0" key={item.id}>
<div className="mt-4 first:mt-0 content-visibility-auto" key={item.id}>
<TranscriptItemView
agentName={agentName}
item={item}

View File

@@ -36,6 +36,9 @@ export function ChannelCanvas({
const [draft, setDraft] = React.useState("");
const canvasContent = canvasQuery.data?.content ?? null;
// Defer the single large Markdown parse so opening the canvas commits the
// surrounding chrome immediately and the heavy render reconciles after.
const deferredCanvasContent = React.useDeferredValue(canvasContent);
function handleStartEditing() {
setDraft(canvasContent ?? "");
@@ -121,7 +124,10 @@ export function ChannelCanvas({
className="rounded-2xl border border-border/70 bg-muted/20 px-4 py-3"
data-testid="channel-canvas-content"
>
<Markdown channelNames={channelNames} content={canvasContent} />
<Markdown
channelNames={channelNames}
content={deferredCanvasContent ?? ""}
/>
</div>
) : (
<p className="text-sm text-muted-foreground">

View File

@@ -432,46 +432,47 @@ export function MembersSidebar({
function renderMemberCard(member: ChannelMember, memberIsBot: boolean) {
return (
<MembersSidebarMemberCard
canChangeRole={canManageMembers && member.pubkey !== currentPubkey}
canRemoveMember={canRemoveMember(member)}
isActionPending={isActionPending || changeRoleMutation.isPending}
isArchived={isArchived}
key={member.pubkey}
managedAgent={
memberIsBot
? managedAgentByPubkey.get(normalizePubkey(member.pubkey))
: undefined
}
member={member}
memberIsBot={memberIsBot}
memberAvatarLabel={member.displayName ?? formatPubkey(member.pubkey)}
memberLabel={formatMemberName(member, currentPubkey)}
onChangeRole={(m, role) => {
void changeRoleMutation.mutateAsync({ pubkey: m.pubkey, role });
}}
onEditRespondTo={memberIsBot ? setEditRespondToAgent : undefined}
onManagedAgentAction={(agent) => {
void handleAgentLifecycleAction(agent);
}}
onOpenProfile={handleOpenProfile}
onRemoveMember={handleRemoveMember}
onViewActivity={
onViewActivity
? (pubkey: string) => {
onOpenChange(false);
onViewActivity(pubkey);
}
: undefined
}
presenceStatus={
memberPresenceQuery.data?.[member.pubkey.toLowerCase()] ?? null
}
profileAvatarUrl={
memberProfilesQuery.data?.profiles[member.pubkey.toLowerCase()]
?.avatarUrl ?? null
}
/>
<div className="content-visibility-auto" key={member.pubkey}>
<MembersSidebarMemberCard
canChangeRole={canManageMembers && member.pubkey !== currentPubkey}
canRemoveMember={canRemoveMember(member)}
isActionPending={isActionPending || changeRoleMutation.isPending}
isArchived={isArchived}
managedAgent={
memberIsBot
? managedAgentByPubkey.get(normalizePubkey(member.pubkey))
: undefined
}
member={member}
memberIsBot={memberIsBot}
memberAvatarLabel={member.displayName ?? formatPubkey(member.pubkey)}
memberLabel={formatMemberName(member, currentPubkey)}
onChangeRole={(m, role) => {
void changeRoleMutation.mutateAsync({ pubkey: m.pubkey, role });
}}
onEditRespondTo={memberIsBot ? setEditRespondToAgent : undefined}
onManagedAgentAction={(agent) => {
void handleAgentLifecycleAction(agent);
}}
onOpenProfile={handleOpenProfile}
onRemoveMember={handleRemoveMember}
onViewActivity={
onViewActivity
? (pubkey: string) => {
onOpenChange(false);
onViewActivity(pubkey);
}
: undefined
}
presenceStatus={
memberPresenceQuery.data?.[member.pubkey.toLowerCase()] ?? null
}
profileAvatarUrl={
memberProfilesQuery.data?.profiles[member.pubkey.toLowerCase()]
?.avatarUrl ?? null
}
/>
</div>
);
}

View File

@@ -1,10 +1,33 @@
import data from "@emoji-mart/data";
import Picker from "@emoji-mart/react";
import { init } from "emoji-mart";
import * as React from "react";
import { buildCustomEmojiCategory } from "@/features/custom-emoji/emojiMartCategory";
import { useCustomEmoji } from "@/features/custom-emoji/hooks";
// emoji-mart builds its searchable index synchronously inside `init`, which
// `<Picker>` calls on mount — so the first reaction popover open paid the full
// ~1.8k-emoji index build and froze the cursor. Warm `init({ data })` once at
// idle so the index is prebuilt; `init` is a no-op after the first call (its
// `Data` singleton guards the rebuild), so the Picker's mount-time `init` skips
// the heavy work. Search still reads the prebuilt index — no first-keystroke
// hitch. Module-level so it fires regardless of when a picker first mounts.
let warmStarted = false;
function warmEmojiIndex() {
if (warmStarted) {
return;
}
warmStarted = true;
const warm = () => void init({ data });
if (typeof window !== "undefined" && "requestIdleCallback" in window) {
window.requestIdleCallback(warm, { timeout: 1_500 });
} else {
globalThis.setTimeout(warm, 250);
}
}
warmEmojiIndex();
/**
* The one emoji picker for the whole app. Every place that lets a user choose
* an emoji — composing a message, reacting to a regular or system message,

View File

@@ -75,7 +75,10 @@ function ReplyRow({
const replyMentionNames = resolveMentionNames(reply.tags, profiles);
return (
<div className="group px-4 py-3" data-forum-event-id={reply.eventId}>
<div
className="group content-visibility-auto px-4 py-3"
data-forum-event-id={reply.eventId}
>
<div className="flex items-center gap-2">
<UserProfilePopover pubkey={reply.pubkey}>
<button

View File

@@ -7,6 +7,7 @@ import type { Channel } from "@/shared/api/types";
import { channelChrome } from "@/shared/layout/chromeLayout";
import { cn } from "@/shared/lib/cn";
import { Skeleton } from "@/shared/ui/skeleton";
import { VirtualizedList } from "@/shared/ui/VirtualizedList";
import {
useCreateForumPostMutation,
@@ -47,6 +48,7 @@ export function ForumView({
targetReplyId,
}: ForumViewProps) {
const [isComposerOpen, setIsComposerOpen] = React.useState(false);
const postsScrollRef = React.useRef<HTMLDivElement>(null);
const profileQuery = useProfileQuery();
const postsQuery = useForumPostsQuery(channel);
@@ -185,6 +187,7 @@ export function ForumView({
<div
className="flex-1 overflow-y-auto"
data-scroll-restoration-id={`forum-list:${channel.id}`}
ref={postsScrollRef}
>
{postsQuery.isLoading ? (
<div className="space-y-3 p-4">
@@ -205,26 +208,32 @@ export function ForumView({
</div>
</div>
) : (
<div className="space-y-3 p-4">
{posts.map((post) => (
<ForumPostCard
canDelete={canDelete(post.pubkey, effectiveCurrentPubkey)}
currentPubkey={effectiveCurrentPubkey}
isActive={selectedPostId === post.eventId}
isDeleting={
deletePostMutation.isPending &&
deletePostMutation.variables?.eventId === post.eventId
}
key={post.eventId}
onClick={() => onSelectPost(post.eventId)}
onDelete={(eventId) => {
deletePostMutation.mutate({ eventId });
}}
post={post}
profiles={profiles}
/>
))}
</div>
<VirtualizedList
estimateSize={120}
getItemKey={(post) => post.eventId}
innerClassName="p-4"
items={posts}
renderItem={(post) => (
<div className="pb-3">
<ForumPostCard
canDelete={canDelete(post.pubkey, effectiveCurrentPubkey)}
currentPubkey={effectiveCurrentPubkey}
isActive={selectedPostId === post.eventId}
isDeleting={
deletePostMutation.isPending &&
deletePostMutation.variables?.eventId === post.eventId
}
onClick={() => onSelectPost(post.eventId)}
onDelete={(eventId) => {
deletePostMutation.mutate({ eventId });
}}
post={post}
profiles={profiles}
/>
</div>
)}
scrollRef={postsScrollRef}
/>
)}
</div>
</div>

View File

@@ -1,4 +1,5 @@
import { ChevronDown, Inbox } from "lucide-react";
import * as React from "react";
import {
formatInboxTypeLabel,
@@ -18,6 +19,7 @@ import {
DropdownMenuTrigger,
} from "@/shared/ui/dropdown-menu";
import { UserAvatar } from "@/shared/ui/UserAvatar";
import { VirtualizedList } from "@/shared/ui/VirtualizedList";
const FILTER_OPTIONS: Array<{ label: string; value: InboxFilter }> = [
{ value: "all", label: "All" },
@@ -47,6 +49,91 @@ export function InboxListPane({
showRightDivider = false,
}: InboxListPaneProps) {
const activeFilter = FILTER_OPTIONS.find((option) => option.value === filter);
const scrollRef = React.useRef<HTMLDivElement>(null);
const renderItem = (item: InboxItem) => {
const isSelected = item.id === selectedId;
const isDone = doneSet.has(item.id);
const typeLabel = formatInboxTypeLabel(item);
return (
<button
className={cn(
"flex w-full items-start gap-2.5 border-l px-5 py-2 text-left transition-colors",
isSelected
? "border-l-transparent bg-muted/30"
: "border-l-transparent hover:bg-muted/25 active:bg-muted/40",
)}
data-testid={`home-inbox-item-${item.id}`}
onClick={() => onSelect(item.id)}
type="button"
>
<div className="relative">
<UserAvatar
avatarUrl={item.avatarUrl}
className="h-8 w-8"
displayName={item.senderLabel}
size="md"
/>
{!isDone ? (
<span className="absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full border-2 border-background bg-primary" />
) : null}
</div>
<div className="min-w-0 flex-1">
<div className="flex items-start gap-2">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<p className="truncate text-sm font-semibold text-foreground">
{item.senderLabel}
</p>
{item.isActionRequired ? (
<span className="inline-flex shrink-0 items-center text-2xs font-semibold uppercase tracking-[0.14em] text-amber-600 dark:text-amber-300">
Needs action
</span>
) : null}
</div>
</div>
<span
className={cn(
"shrink-0 text-xs text-muted-foreground",
isDone ? "font-normal" : "font-semibold",
)}
>
{item.timestampLabel}
</span>
</div>
<div
className={cn(
"mt-0.5 line-clamp-2 text-sm leading-5 **:inline [&_a]:font-medium [&_a]:text-current [&_br]:hidden [&_p]:inline",
isDone
? "font-normal text-muted-foreground"
: "font-semibold text-foreground",
)}
>
<Markdown
className="inline max-w-full text-inherit"
content={item.preview}
interactive={false}
mentionNames={item.mentionNames}
/>
</div>
<div className="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<span
className={cn(
"text-2xs text-muted-foreground",
isDone ? "font-normal" : "font-semibold",
)}
>
{typeLabel}
</span>
</div>
</div>
</button>
);
};
return (
<section
@@ -101,6 +188,7 @@ export function InboxListPane({
<div
className="min-h-0 flex-1 overflow-y-auto overscroll-contain"
data-testid="home-inbox-list"
ref={scrollRef}
>
{items.length === 0 ? (
<div className="flex h-full min-h-64 items-center justify-center px-6 text-center">
@@ -114,92 +202,13 @@ export function InboxListPane({
</div>
</div>
) : (
<div>
{items.map((item) => {
const isSelected = item.id === selectedId;
const isDone = doneSet.has(item.id);
const typeLabel = formatInboxTypeLabel(item);
return (
<button
className={cn(
"flex w-full items-start gap-2.5 border-l px-5 py-2 text-left transition-colors",
isSelected
? "border-l-transparent bg-muted/30"
: "border-l-transparent hover:bg-muted/25 active:bg-muted/40",
)}
data-testid={`home-inbox-item-${item.id}`}
key={item.id}
onClick={() => onSelect(item.id)}
type="button"
>
<div className="relative">
<UserAvatar
avatarUrl={item.avatarUrl}
className="h-8 w-8"
displayName={item.senderLabel}
size="md"
/>
{!isDone ? (
<span className="absolute -right-1 -top-1 h-2.5 w-2.5 rounded-full border-2 border-background bg-primary" />
) : null}
</div>
<div className="min-w-0 flex-1">
<div className="flex items-start gap-2">
<div className="min-w-0 flex-1">
<div className="flex items-center gap-2">
<p className="truncate text-sm font-semibold text-foreground">
{item.senderLabel}
</p>
{item.isActionRequired ? (
<span className="inline-flex shrink-0 items-center text-2xs font-semibold uppercase tracking-[0.14em] text-amber-600 dark:text-amber-300">
Needs action
</span>
) : null}
</div>
</div>
<span
className={cn(
"shrink-0 text-xs text-muted-foreground",
isDone ? "font-normal" : "font-semibold",
)}
>
{item.timestampLabel}
</span>
</div>
<div
className={cn(
"mt-0.5 line-clamp-2 text-sm leading-5 **:inline [&_a]:font-medium [&_a]:text-current [&_br]:hidden [&_p]:inline",
isDone
? "font-normal text-muted-foreground"
: "font-semibold text-foreground",
)}
>
<Markdown
className="inline max-w-full text-inherit"
content={item.preview}
interactive={false}
mentionNames={item.mentionNames}
/>
</div>
<div className="mt-1 flex flex-wrap items-center gap-2 text-xs text-muted-foreground">
<span
className={cn(
"text-2xs text-muted-foreground",
isDone ? "font-normal" : "font-semibold",
)}
>
{typeLabel}
</span>
</div>
</div>
</button>
);
})}
</div>
<VirtualizedList
estimateSize={76}
getItemKey={(item) => item.id}
items={items}
renderItem={renderItem}
scrollRef={scrollRef}
/>
)}
</div>
</section>

View File

@@ -29,6 +29,7 @@ import type { ChannelMember, UserProfileSummary } from "@/shared/api/types";
import { Input } from "@/shared/ui/input";
import { Skeleton } from "@/shared/ui/skeleton";
import { UserAvatar } from "@/shared/ui/UserAvatar";
import { VirtualizedList } from "@/shared/ui/VirtualizedList";
export type PulseTab =
| "search"
@@ -73,6 +74,7 @@ function TimelineSkeleton() {
export function PulseView({ currentPubkey }: PulseViewProps) {
const [activeTab, setActiveTab] = React.useState<PulseTab>("everyone");
const [searchQuery, setSearchQuery] = React.useState("");
const scrollRef = React.useRef<HTMLDivElement>(null);
const contactListQuery = useContactListQuery(currentPubkey);
const contacts = contactListQuery.data?.contacts ?? [];
const contactPubkeys = React.useMemo(
@@ -268,43 +270,57 @@ export function PulseView({ currentPubkey }: PulseViewProps) {
return agentNoteGroups.length === 0 ? (
<EmptyState message={emptyMessages.agents} />
) : (
agentNoteGroups.map((group) => (
<AgentActivityCard
agentStatus={agentStatusMap[group.pubkey]}
group={group}
key={`${group.pubkey}-${group.latestAt}`}
profile={profiles[group.pubkey.toLowerCase()] ?? null}
/>
))
<VirtualizedList
estimateSize={160}
getItemKey={(group) => `${group.pubkey}-${group.latestAt}`}
items={agentNoteGroups}
renderItem={(group) => (
<div className="pb-4">
<AgentActivityCard
agentStatus={agentStatusMap[group.pubkey]}
group={group}
profile={profiles[group.pubkey.toLowerCase()] ?? null}
/>
</div>
)}
scrollRef={scrollRef}
/>
);
}
return visibleNotes.length === 0 ? (
<EmptyState message={emptyMessages[activeTab]} />
) : (
visibleNotes.map((note) => (
<NoteCard
actions={{
reply: noteActions.reply,
share: noteActions.share,
startDm: noteActions.startDm,
toggleUpvote: noteActions.toggleUpvote,
}}
composerProfiles={mentionProfiles}
currentUserDisplayName={currentDisplayName}
currentUserProfile={currentProfile}
isAgent={agentPubkeySet.has(note.pubkey)}
isOwnNote={note.pubkey === currentPubkey}
isReplySending={noteActions.isReplySending}
isUpvotePending={noteActions.isUpvotePending(note.id)}
isUpvoted={noteActions.isUpvoted(note.id)}
reactionCount={noteActions.reactionCount(note.id)}
key={note.id}
members={pulseMentionMembers}
note={note}
profile={profiles[note.pubkey.toLowerCase()] ?? null}
/>
))
<VirtualizedList
estimateSize={140}
getItemKey={(note) => note.id}
items={visibleNotes}
renderItem={(note) => (
<div className="pb-4">
<NoteCard
actions={{
reply: noteActions.reply,
share: noteActions.share,
startDm: noteActions.startDm,
toggleUpvote: noteActions.toggleUpvote,
}}
composerProfiles={mentionProfiles}
currentUserDisplayName={currentDisplayName}
currentUserProfile={currentProfile}
isAgent={agentPubkeySet.has(note.pubkey)}
isOwnNote={note.pubkey === currentPubkey}
isReplySending={noteActions.isReplySending}
isUpvotePending={noteActions.isUpvotePending(note.id)}
isUpvoted={noteActions.isUpvoted(note.id)}
reactionCount={noteActions.reactionCount(note.id)}
members={pulseMentionMembers}
note={note}
profile={profiles[note.pubkey.toLowerCase()] ?? null}
/>
</div>
)}
scrollRef={scrollRef}
/>
);
}
@@ -318,7 +334,7 @@ export function PulseView({ currentPubkey }: PulseViewProps) {
relayAgents={relayAgents}
/>
<div className="mt-0 min-h-0 flex-1 overflow-y-auto">
<div className="mt-0 min-h-0 flex-1 overflow-y-auto" ref={scrollRef}>
<div
aria-labelledby={pulseTabId(activeTab)}
className={`mx-auto flex w-full max-w-2xl flex-col px-4 pb-10 sm:px-6 ${
@@ -399,9 +415,7 @@ export function PulseView({ currentPubkey }: PulseViewProps) {
</div>
) : null}
{activeTab !== "search" ? (
<div className="space-y-4">{renderTimeline()}</div>
) : null}
{activeTab !== "search" ? <div>{renderTimeline()}</div> : null}
</div>
</div>
</div>

View File

@@ -36,6 +36,7 @@ import {
DropdownMenuTrigger,
} from "@/shared/ui/dropdown-menu";
import { Input } from "@/shared/ui/input";
import { VirtualizedList } from "@/shared/ui/VirtualizedList";
type AssignableRelayRole = Exclude<RelayMemberRole, "owner">;
@@ -486,17 +487,22 @@ export function RelayMembersSettingsCard({
No members match your search.
</p>
) : (
<div className="max-h-[28rem] space-y-2 overflow-y-auto pr-1">
{filteredMembers.map((member) => (
<RelayMemberRow
currentPubkey={currentPubkey}
currentRole={currentRole}
key={member.pubkey}
member={member}
profile={profiles?.[normalizePubkey(member.pubkey)]}
/>
))}
</div>
<VirtualizedList
className="max-h-[28rem] pr-1"
estimateSize={56}
getItemKey={(member) => member.pubkey}
items={filteredMembers}
renderItem={(member) => (
<div className="pb-2">
<RelayMemberRow
currentPubkey={currentPubkey}
currentRole={currentRole}
member={member}
profile={profiles?.[normalizePubkey(member.pubkey)]}
/>
</div>
)}
/>
)}
</div>
</div>

View File

@@ -363,7 +363,7 @@ export function ChannelGroupSection({
{items.map((channel) => (
<ContextMenu key={channel.id}>
<ContextMenuTrigger asChild>
<SidebarMenuItem>
<SidebarMenuItem className="content-visibility-auto-row">
{draggable ? (
<DraggableChannelRow channelId={channel.id}>
<ChannelMenuButton