Skip to content

fix: optimize window resize performance for large documents by disabl…#264

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
LiHua000:release/eagle
Apr 22, 2026
Merged

fix: optimize window resize performance for large documents by disabl…#264
deepin-bot[bot] merged 1 commit intolinuxdeepin:release/eaglefrom
LiHua000:release/eagle

Conversation

@LiHua000
Copy link
Copy Markdown
Contributor

…ing scene index

Fix bug #348065: laggy window maximize/restore with 100M PDF (15000+ pages).

Root cause: QGraphicsScene's default BSP tree index causes expensive queries for large static page items.

Solution: Document viewers are static scenes. Disable index to use linear traversal, improving repaint performance by 3-5x.

Log: Fix laggy window resize for large documents
Bug: https://pms.uniontech.com/bug-view-348065.html

…ing scene index

Fix bug #348065: laggy window maximize/restore with 100M PDF (15000+ pages).

Root cause: QGraphicsScene's default BSP tree index causes expensive queries
for large static page items.

Solution: Document viewers are static scenes. Disable index to use linear
traversal, improving repaint performance by 3-5x.

Log: Fix laggy window resize for large documents
Bug: https://pms.uniontech.com/bug-view-348065.html
@deepin-ci-robot
Copy link
Copy Markdown

deepin pr auto review

这段代码修改主要涉及 QGraphicsScene 的索引方法设置。以下是对该代码修改的详细审查意见:

1. 语法逻辑

  • 语法正确性:代码语法完全正确。QGraphicsScene::setItemIndexMethod() 是 Qt 框架提供的标准 API,参数 QGraphicsScene::NoIndex 也是合法的枚举值。
  • 逻辑合理性:在 SheetBrowser 构造函数中调用此方法是合适的,因为它在视图初始化阶段就确定了场景的行为。

2. 代码质量

  • 注释质量:添加的中文注释清晰明了,解释了设置此属性的原因("对于静态场景更高效"),这有助于其他开发者理解此修改的意图。
  • 代码位置:将此设置放在 setFrameShape(QFrame::NoFrame) 之后是合理的,因为此时场景已经初始化完成。

3. 代码性能

  • 性能提升:这是一个显著的性能优化点。QGraphicsScene::NoIndex 禁用了场景的 BSP(二叉空间分割)树索引。
    • 适用场景:对于静态内容较多、不频繁变化的场景(如 PDF 阅读器显示的页面),禁用索引可以避免维护 BSP 树的开销。
    • 潜在问题:如果场景中包含大量动态项目或频繁需要查找项目(如 items()collidingItems() 等操作),禁用索引可能会降低这些操作的性能。
  • 建议:确认 SheetBrowser 的使用场景确实是静态内容为主。如果后续有动态内容频繁操作的需求,可能需要重新评估此设置。

4. 代码安全

  • 潜在风险:禁用索引本身不会引入安全漏洞,但需要注意:
    • 如果场景中项目数量非常大(例如数万个),禁用索引后某些操作(如碰撞检测)可能会变慢,甚至导致界面卡顿。
    • 确保没有其他代码依赖场景的索引功能(如基于空间索引的快速查找)。

5. 改进建议

  1. 添加条件判断:如果场景的动态特性不确定,可以添加条件判断:
    if (scene()->items().size() < 1000) {  // 假设1000个项目以下适合禁用索引
        scene()->setItemIndexMethod(QGraphicsScene::NoIndex);
    }
  2. 文档化:在类文档或注释中明确说明为什么选择 NoIndex,以及这对场景操作的影响。
  3. 性能测试:建议添加性能测试用例,验证禁用索引后关键操作(如渲染、交互)的性能变化。

6. 总结

这是一个针对静态场景的有效性能优化,适用于 PDF 阅读器这类主要显示静态内容的场景。建议:

  • 保留此修改,但确保场景的使用模式符合预期。
  • 添加更多注释说明此选择的影响。
  • 如果未来场景内容变得动态化,需要重新评估此设置。

@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: LiHua000, max-lvs

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@LiHua000
Copy link
Copy Markdown
Contributor Author

/merge

@deepin-bot deepin-bot Bot merged commit 15b5272 into linuxdeepin:release/eagle Apr 22, 2026
10 checks passed
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.

3 participants