perf(desktop): 按可见页懒渲染 PDF 并限制画布像素开销 - #4057
Merged
Merged
Conversation
|
| Filename | Overview |
|---|---|
| apps/desktop/src/renderer/features/cc-agent/workdir-browse/PdfPreview.tsx | 新增按可见区域懒渲染、canvas 像素预算及资源清理,但仍会按总页数一次性挂载全部页面组件和占位 DOM。 |
| apps/desktop/src/renderer/features/cc-agent/workdir-browse/tests/PdfPreview.test.tsx | 覆盖像素预算、混宽对齐、离屏取消、文档替换及错误清理,但未覆盖高页数文档的挂载开销。 |
| apps/desktop/src/main/cindy-media/tests/blobStore.test.ts | 增加 Windows 文件链接能力探测、目录 junction 适配及不依赖链接权限的注入安全测试。 |
| apps/desktop/src/main/cindy-media/tests/ingest.test.ts | 增加文件 symlink 能力探测,并验证注入 symlink 元数据后的字节与账本零副作用。 |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[读取并解析 PDF] --> B[取得 pdf.numPages]
B --> C[一次性挂载全部 PdfPage 占位节点]
C --> D[IntersectionObserver 观察全部页面]
D --> E{页面进入预取区域?}
E -- 是 --> F[getPage 并创建 canvas]
F --> G[按 DPR 与 400 万像素预算渲染]
E -- 否 --> H[保留页面占位节点]
G --> I{页面离开区域?}
I -- 是 --> J[取消任务并释放 canvas]
I -- 否 --> G
Prompt To Fix All With AI
### Issue 1
apps/desktop/src/renderer/features/cc-agent/workdir-browse/PdfPreview.tsx:426
**高页数仍全量挂载**
这里虽然只为可见页面绘制 canvas,但仍会按 `pdf.numPages` 一次性创建全部 `PdfPage` 组件、占位节点和观察目标。读取限制只约束 PDF 文件不超过 30 MiB,并不限制页数,因此包含数千乃至数万张简化页面的合法 PDF 仍可能在打开时建立同等规模的组件树和布局,导致渲染器长时间阻塞或内存耗尽。需要虚拟化页面占位,或明确限制可挂载的页数。
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Reviews (1): Last reviewed commit: "test(desktop): cover media symlink safet..." | Re-trigger Greptile
Signed-off-by: DavidShen <david@xd.com>
Observe any intersection so oversized PDF pages remain rendered after their placeholders expand. Cover low visible-area ratios, repeated viewport re-entry, canvas release and the per-page pixel budget. Signed-off-by: DavidShen <david@xd.com>
Keep mixed-width pages on a shared left edge so visible placeholders remain observable. Bound integer canvas dimensions for thin pages and avoid ratio overflow on huge finite viewports. Add regression coverage for both cases. Signed-off-by: DavidShen <david@xd.com>
Exercise permission-independent rejection, post-read replacement, handle cleanup and ledger side effects alongside the shared filesystem fixtures. Signed-off-by: DavidShen <david@xd.com>
DavidShenXD
force-pushed
the
cindy/vibrant-jepsen
branch
from
September 7, 2026 12:01
3582d09 to
e8bce29
Compare
Collaborator
Author
反馈已处理已处理:
变更:
验证:
备注:
|
Collaborator
Author
反馈已处理已处理:
变更:
验证:
备注:
|
Contributor
|
命中 UI 路径(apps/desktop/src/renderer/features/cc-agent/workdir-browse/PdfPreview.tsx)但 description 未附界面效果证据——建议补充改动后效果:截图/录屏,或改动后界面的 HTML 页面(```html 代码块、.html 附件或在线预览链接),便于确认界面符合 DESIGN.md 设计规范 |
Collaborator
Author
反馈已处理已处理:
变更:
验证:
备注:
|
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
这次改了什么
摘要
工作区 PDF 预览改为只为可见页及上下 400px 的邻近页面请求页面资源、创建和绘制 canvas,避免打开长 PDF 就逐页绘制整份文档。
变更类型
fix缺陷修复refactor/perf重构或性能优化docs/test/chore测试补充范围
PdfPreview.tsx、对应单测,以及blobStore.test.ts/ingest.test.ts的额外安全检查。UI 变化
docs/design-rules/DESIGN.md§1 最小化界面和 §10 Light / Dark 双模式交付门槛、语义 token。保留原阅读尺寸、白纸与页面间距,外围继续使用--surface,不增加反色处理或单主题补丁;共同左对齐恢复原页面排列语义。改动后界面效果证据(真实截图)
2b2814a4e59a4edeb982825cfdce5c40b8f089b0;当前 HEAD 为e8bce295d237ea4d275b0354247caa53db82fd33。已核对两者PdfPreview.tsxGit blob 完全相同(8f6c2c25a8c5e70cff3c0141b9767d96d9e8c446),本轮复用已有验收证据,并未重新运行黑盒。pdf-preview-evidence.html后用浏览器打开;图片已内嵌,无脚本、无外部网络请求、无需安装依赖。这里只交证据,不代替设计师批准;截图不能单独证明运行时性能。展开自包含 HTML 截图证据页(Light / Dark / 长 PDF / 超大页)
怎么验证的
自动验证
2026-09-07:已 rebase 到 main 的
f6c037cc9,最新提交e8bce295d。手工验证
本轮 rebase 未重新启动黑盒验收:PDF 源码和对应单测与重基前逐字一致,已补跑上述检查。以下保留重基前正式黑盒记录。
2026-09-07,当前独立 worktree 的 Global 隔离沙盒,Windows / Electron 41.10.3 / 原生 DPR=1。PDF 运行时代码对应
2b2814a4e(后续3582d09fe仅改媒体单测)。通过应用正常预览路径、原生滚动输入和主题设置验收,不覆盖 IntersectionObserver,不使用 DPR 模拟或强制 GC。最终 23 个检查点全部通过,本轮新增未处理异常为 0。未执行的验证
风险
风险分类
影响与回滚
提交前检查