Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

perf(chat): 视口外消息条目跳过布局绘制(content-visibility)

david902fe3cb664c
diff --git a/apps/desktop/src/renderer/components/chat/MessageStream.tsx b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
index cc2048e767..abd3d3245d 100644
--- a/apps/desktop/src/renderer/components/chat/MessageStream.tsx
+++ b/apps/desktop/src/renderer/components/chat/MessageStream.tsx
@@ -3790,7 +3790,12 @@ export function MessageStream({
<div
ref={itemsRef}
className={cn(
- 'flex flex-col gap-3.5',
+ // msg-stream-items:直接子元素(每条 render item 的根节点)带
+ // content-visibility:auto(globals.css)—— 视口外条目跳过布局
+ // 与绘制,切入长 session 的首帧成本从「整个窗口 80 条」降到
+ // 「一屏」。滚动恢复按条目锚定 + ResizeObserver 纠偏,估高
+ // (240px)与真实高度的偏差在条目进入视口后被自动纠正。
+ 'msg-stream-items flex flex-col gap-3.5',
// 分享选择模式:整列内容右移,左侧让出复选框那一列。缩进加在
// 容器上(不是逐条消息),工具卡等不可选的 item 也跟着移,
// 左边缘保持对齐。
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index 9305c77830..078dcdbef1 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -1146,6 +1146,21 @@ body.resizing-pane [data-ghost-webview] {
}
}
+/* 消息流条目级渲染跳过(Codex Desktop 同款,2026-08-09):视口外的 render
+ item 跳过整棵子树的布局与绘制,只按 contain-intrinsic-size 估高占位
+ (auto 前缀:渲染过一次后记住真实高度,滚回时用真实值,锚点不漂)。
+ 切入长 session 时首帧只需布局视口内的几条消息 —— 之前是渲染窗口全量
+ 80 条同步布局,几万字的会话切换有数百毫秒长任务(2026-08-09 实测卡顿)。
+ 仅作用于 .msg-stream-items 的直接子元素(每条 render item 的根节点):
+ 滚动恢复(measureViewportTop/applyRestore)按 children 索引取
+ getBoundingClientRect —— 对 content-visibility 隐藏的条目返回估高盒,
+ 量测仍然成立,进入视口后 ResizeObserver 纠偏收敛到真实高度。
+ 打印/导出走独立渲染树,不经过本容器,不受影响。 */
+.msg-stream-items > * {
+ content-visibility: auto;
+ contain-intrinsic-size: auto 240px;
+}
+
/* 意识卡片 running 扫光(卡槽③):主机盖在意识画布上的斜向光带。
transform-only(规则 7 compositor-only);仅 running 挂载,settle 即卸,
历史卡永远静止(净化器已剥意识自带动画,动感统一由主机供给)。 */