perf(client): 有界缓存与每秒再渲染收敛(#935 遗留项)
keepMounted 下「只增不减」的模块级表等于内存单调增长;每秒换新对象的 setState 等于每秒重建整份列表。 - git-status:槽位参与淘汰——释放归零即删(有在飞请求则等它结算),mint 顺序上限 256,只淘汰 visible===0 && 无在飞 的槽;retain 会重新登记被遗忘的槽对象, 同一键永不出现两条轮询器。30s 基线 / 退档 / poll:false 不持表 / 空闲不 notify 不变。 - ops-stream:streams 加 LRU 32(只淘汰无成员的记录),保留 seq/primed 游标—— parked 页签回来仍能折到错过的那次写操作;被挤出去才重新基线(与刷新同代价)。 - TextEditor.previewScrollMemory 64、GitLens.commitDrafts 32(提交失败仍保留草稿)、 markdown-navigation.pendingAnchors 改为写入时按 TTL 清扫。 - JobsDrawer:1s 时钟抽成自持 state 的 memo 组件并按 visible + document.hidden 门控, 行列表不再依赖走秒值;行的无障碍名不再逐秒变化。 - SubagentView:同值保持引用 + published ref 拦掉 dispatch(实测仅靠 updater 形式 React 仍会提交一次),模型/图派生因此不再每 tick 重算。 - GitLens:silent tick 改为「同值不换引用」而不是把 setWorktrees 挪到早退之后—— 后者会让中途新建的 linked checkout 在 silent tick 上永远冻结。 测试:扩展 git-status-poll / subagent-live-polling / subagent-jobs-view,新增 unbounded-caches;每条都用「临时回退→变红→还原」验过。
This commit is contained in:
1 parent
3e5576ffbb
commit
ea3a016161
11 files changed
+944
-55
No files matched your search
@@ -95,6 +95,55 @@ function errorMessage(reason: unknown): string {
|
||||
return reason instanceof Error ? reason.message : String(reason)
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether two inventory listings say the same thing. Every listing pass answers
|
||||
* with a fresh array of fresh rows, so identity alone would republish on each
|
||||
* poll; a field-by-field compare is what lets an unchanged silent tick stay
|
||||
* silent (see `runOnce`).
|
||||
*/
|
||||
function sameWorktrees(left: readonly GitWorktree[], right: readonly GitWorktree[]): boolean {
|
||||
if (left === right) return true
|
||||
if (left.length !== right.length) return false
|
||||
return left.every((entry, index) => {
|
||||
const other = right[index]!
|
||||
return entry.path === other.path && entry.branch === other.branch
|
||||
&& entry.current === other.current && entry.changes === other.changes
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* How many scopes' commit drafts are remembered. The lens is a kept-mounted tab
|
||||
* body, so this record lives for the page: without a bound, a session that
|
||||
* walked through many projects would pin one message per project forever.
|
||||
*/
|
||||
export const COMMIT_DRAFT_CAP = 32
|
||||
|
||||
/**
|
||||
* Write one scope's draft into the record, remembering at most
|
||||
* {@link COMMIT_DRAFT_CAP} scopes. Re-writing a key moves it to the back, so
|
||||
* the draft evicted past the cap is the scope typed into longest ago — a typed
|
||||
* message for another project is never what a commit here submits (the record
|
||||
* is keyed by scope, and `commit()` reads only its own key).
|
||||
*
|
||||
* @param prev - the current record (never mutated).
|
||||
* @param key - the scope key (session + cwd).
|
||||
* @param text - the draft (`''` = cleared; the key stays, so it reads back as
|
||||
* an empty box rather than as a missing one).
|
||||
* @returns the next record.
|
||||
*/
|
||||
export function withCommitDraft(
|
||||
prev: Record<string, string>,
|
||||
key: string,
|
||||
text: string,
|
||||
): Record<string, string> {
|
||||
const next: Record<string, string> = { ...prev }
|
||||
delete next[key]
|
||||
next[key] = text
|
||||
const keys = Object.keys(next)
|
||||
for (const stale of keys.slice(0, Math.max(0, keys.length - COMMIT_DRAFT_CAP))) delete next[stale]
|
||||
return next
|
||||
}
|
||||
|
||||
/** The pending destructive action (discard / revert / cherry-pick), gated by a confirm dialog. */
|
||||
interface ConfirmState {
|
||||
title: string
|
||||
@@ -346,12 +395,13 @@ export function GitLens(props: GitLensProps) {
|
||||
* and a staged row, so a draft typed against another project would submit
|
||||
* verbatim under this one. Keyed rather than cleared on a scope swap, so a
|
||||
* kept-mounted tab shows a conversation its own message when it comes back
|
||||
* (#712). */
|
||||
* (#712) — bounded to the newest {@link COMMIT_DRAFT_CAP} scopes, because
|
||||
* that tab lives for the whole page. */
|
||||
const [commitDrafts, setCommitDrafts] = useState<Record<string, string>>({})
|
||||
const draftKey = `${scope.sessionId}\u0000${scope.cwd ?? ''}`
|
||||
const commitMsg = commitDrafts[draftKey] ?? ''
|
||||
const writeDraft = (text: string): void => {
|
||||
setCommitDrafts(prev => ({ ...prev, [draftKey]: text }))
|
||||
setCommitDrafts(prev => withCommitDraft(prev, draftKey, text))
|
||||
}
|
||||
const [busy, setBusy] = useState(false)
|
||||
/** Whether a commit-message suggestion is being generated host-side (the
|
||||
@@ -503,7 +553,13 @@ export function GitLens(props: GitLensProps) {
|
||||
return
|
||||
}
|
||||
if (signal?.aborted === true || generation !== scopeGen.current) return
|
||||
setWorktrees(listed)
|
||||
// Republish the inventory only when it really says something new. Handing
|
||||
// React a fresh array (and fresh rows) on every 30 s tick re-rendered the
|
||||
// whole lens — the change trees included — although nothing had changed,
|
||||
// which is exactly what the "silent" tick below was supposed to avoid.
|
||||
// Keeping the previous identity when the listing is equal makes the tick
|
||||
// silent; a new linked checkout or a moved change count still lands.
|
||||
setWorktrees(previous => (sameWorktrees(previous, listed) ? previous : listed))
|
||||
const current = listed.find(entry => entry.current)
|
||||
const stillListed = chosenPathRef.current !== undefined
|
||||
&& listed.some(entry => entry.path === chosenPathRef.current)
|
||||
|
||||
Reference in new issue
Block a user