Skip to content

[0168] 改进 PDF 阅读器性能#3527

Draft
da-liii wants to merge 4 commits into
mainfrom
da/0168/pdf_perf
Draft

[0168] 改进 PDF 阅读器性能#3527
da-liii wants to merge 4 commits into
mainfrom
da/0168/pdf_perf

Conversation

@da-liii
Copy link
Copy Markdown
Contributor

@da-liii da-liii commented May 27, 2026

改进内容

  1. PDF 文档常驻内存

    • fz_document/fz_stream/fz_buffer 提升为成员变量,在 loadFromFile 时打开并保持到 clear() 才释放。
    • renderPageToLabelextractPageLinks 直接复用已打开的文档句柄,消除每次渲染重复 fz_open_document_with_stream 的巨大开销。
  2. LRU 缓存淘汰

    • QHash<PdfPageCacheKey, QPixmap> 替换为 QCache,默认上限 30 条,自动 LRU 淘汰。
    • 防止大文档反复缩放时内存无限增长。
  3. 懒加载尺寸调整

    • applyZoomToLabels 改为仅调整可见及 PRELOAD_MARGIN 范围内的 label 尺寸。
    • 避免 pinch 缩放过程中遍历全部页面 label。

测试

  • 全部 41 个单元测试通过。
  • 新增 2 个缓存相关单元测试:
    • test_cacheRespectsMaxSize
    • test_cacheDoesNotGrowUnbounded

提交历史

  • [0168] PDF文档常驻内存,避免每次渲染重新打开
  • [0168] LRU缓存与懒加载尺寸调整
  • [0168] 更新任务文档,标记已完成项

🤖 Generated with Claude Code

da-liii and others added 4 commits May 27, 2026 20:13
将 fz_document/fz_stream/fz_buffer 提升为成员变量,在 loadFromFile
时打开并保持到 clear() 或析构时才释放。renderPageToLabel 和
extractPageLinks 直接复用已打开的文档句柄,消除重复打开文档的
巨大开销。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1. 将页面渲染缓存从 QHash 替换为 QCache,默认上限 30 条,防止
   大文档反复缩放时内存无限增长。添加 cacheSize/cacheMaxSize 测试
   接口和两个单元测试验证淘汰行为。

2. applyZoomToLabels 改为仅调整可见及预加载范围内的 label 尺寸,
   避免大文档在 pinch 缩放过程中遍历所有页面 label。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@MoonL79 MoonL79 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@da-liii da-liii marked this pull request as draft May 28, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants