Skip to content

Commit 9c16146

Browse files
perf(web): pull request chains parse each link's URL once (#21147)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent e0366ad commit 9c16146

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

‎packages/shared/src/threadPullRequests.ts‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,21 @@ export function threadPullRequestKeysEqual(
6969
return threadPullRequestKeyOf(left) === threadPullRequestKeyOf(right);
7070
}
7171

72+
// Clients re-derive chains for every link on each render, and normalizing parses the
73+
// link's URL. Links are immutable and keep their identity until they change.
74+
const normalizedKeys = new WeakMap<ThreadPullRequestKeySource, ThreadPullRequestKey>();
75+
76+
function normalizedKeyOf(key: ThreadPullRequestKeySource): ThreadPullRequestKey {
77+
let normalized = normalizedKeys.get(key);
78+
if (normalized === undefined) {
79+
normalized = normalizeThreadPullRequestKey(key);
80+
normalizedKeys.set(key, normalized);
81+
}
82+
return normalized;
83+
}
84+
7285
export function threadPullRequestKeyOf(key: ThreadPullRequestKeySource): string {
73-
const normalized = normalizeThreadPullRequestKey(key);
86+
const normalized = normalizedKeyOf(key);
7487
return `${normalized.host}/${normalized.repository}#${normalized.number}`;
7588
}
7689

@@ -210,7 +223,7 @@ export function resolveThreadPullRequestChains(
210223
const nativeStacks = new Map<string, Array<ThreadPullRequestLink>>();
211224
for (const link of visible) {
212225
if (link.stack === null) continue;
213-
const key = normalizeThreadPullRequestKey(link);
226+
const key = normalizedKeyOf(link);
214227
const stackKey = `${key.host}/${key.repository}#stack:${link.stack.id}`;
215228
const members = nativeStacks.get(stackKey) ?? [];
216229
members.push(link);
@@ -225,7 +238,7 @@ export function resolveThreadPullRequestChains(
225238

226239
const remaining = visible.filter((link) => !placed.has(threadPullRequestKeyOf(link)));
227240
const branchKey = (link: ThreadPullRequestLink, branch: string) => {
228-
const key = normalizeThreadPullRequestKey(link);
241+
const key = normalizedKeyOf(link);
229242
return `${key.host}/${key.repository}:${branch}`;
230243
};
231244
const byHead = new Map<string, ThreadPullRequestLink | null>();

0 commit comments

Comments
 (0)