mirror of
https://github.com/block/buzz.git
synced 2026-11-30 21:21:48 +00:00
perf(desktop): drop per-row agent-pubkey rescan, use the set passed from parent
Finding [L4] MessageRow resolvedAgentPubkeys (Tier 2): every mounted row re-scanned the full `profiles` lookup to rebuild the agent-pubkey Set, so the same O(profiles) work ran once per row and re-ran on every profile-lookup change. ChannelScreen already computes this exact Set once (now from the stabilised lookup) and passes it down as `agentPubkeys`, already normalised. Consume the passed Set directly, falling back to a module-level stable empty Set so rows without one keep a constant reference (a fresh `new Set()` per render would defeat the row memo). Widen `getConfigNudgeAuthorPubkey`'s parameter to `ReadonlySet<string>` — it only reads via `.has()`, and this matches how the `agentPubkeys` prop is already typed upstream. Co-authored-by: Tyler Longwell <tlongwell@block.xyz> Signed-off-by: Tyler Longwell <tlongwell@block.xyz>
This commit is contained in:
committed by
npub1qyvc0c5kl4gqv2fd97fsk46tu378sqgy35vc83rvgfwne90sel7s0ed67d
parent
3bffd34e83
commit
9628ce7662
@@ -43,6 +43,10 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui/tooltip";
|
||||
const DiffMessage = React.lazy(() => import("./DiffMessage"));
|
||||
const DiffMessageExpanded = React.lazy(() => import("./DiffMessageExpanded"));
|
||||
|
||||
/** Stable empty fallback so rows without an agent-pubkey set keep a constant
|
||||
* reference (a fresh `new Set()` per render would defeat downstream memos). */
|
||||
const EMPTY_AGENT_PUBKEYS: ReadonlySet<string> = new Set();
|
||||
|
||||
export type ThreadDepthGuideAction = {
|
||||
active?: boolean;
|
||||
depth: number;
|
||||
@@ -157,17 +161,11 @@ export const MessageRow = React.memo(
|
||||
() => resolveMentionPubkeysByName(message.tags, profiles),
|
||||
[profiles, message.tags],
|
||||
);
|
||||
const resolvedAgentPubkeys = React.useMemo(() => {
|
||||
const pubkeys = new Set(agentPubkeys ?? []);
|
||||
|
||||
for (const [pubkey, profile] of Object.entries(profiles ?? {})) {
|
||||
if (profile.isAgent) {
|
||||
pubkeys.add(normalizePubkey(pubkey));
|
||||
}
|
||||
}
|
||||
|
||||
return pubkeys;
|
||||
}, [agentPubkeys, profiles]);
|
||||
// The agent-pubkey set is computed once by the parent (ChannelScreen)
|
||||
// from the same profile lookup and passed down already normalised — no
|
||||
// per-row rescan of `profiles` (that duplicated the parent's work in every
|
||||
// mounted row and re-ran on each profile-lookup change).
|
||||
const resolvedAgentPubkeys = agentPubkeys ?? EMPTY_AGENT_PUBKEYS;
|
||||
const profilePopoverRole =
|
||||
message.role === "bot" ||
|
||||
(message.pubkey &&
|
||||
|
||||
@@ -18,7 +18,7 @@ import type { TimelineMessage } from "@/features/messages/types";
|
||||
*/
|
||||
export function getConfigNudgeAuthorPubkey(
|
||||
message: Pick<TimelineMessage, "kind" | "signerPubkey">,
|
||||
resolvedAgentPubkeys: Set<string>,
|
||||
resolvedAgentPubkeys: ReadonlySet<string>,
|
||||
): string | undefined {
|
||||
if (
|
||||
message.kind === KIND_STREAM_MESSAGE &&
|
||||
|
||||
Reference in New Issue
Block a user