perf(ui): render rule models and create detail views on demand

This commit is contained in:
阿白叔 committed 2026-10-15 22:51:10 +08:00
1 parent 84d8f9c7f5
commit ce574ddb44
18 files changed
+693 -170

No files matched your search

@@ -0,0 +1,41 @@
# UI component lifetime review
用户指出页面提前分配和隐藏更新的资源浪费。本轮在现有 Qt Widgets 架构内改动,不更换 UI 框架。
## 已确认的开销
主工作区一直复用同一套组件,不是每个工程复制一套页面。位号表已经使用 Model/View;执行反馈 timer 仅执行期间运行。实际重复开销来自规则表逐行 QWidget/QCheckBox、整表重建,以及启动时预建结果、日志、BOM 详情和隐藏时更新文档。
## 改动
- 规则表改为 QAbstractTableModel/QTableView,无每行 QWidget。相同快照不 reset;同一组规则内容变化发 dataChanged;顺序变化按 rule_id 恢复选择。启用请求仍经后台服务落库,成功后用持久化快照确认,失败不会留下虚假的勾选状态。
- 替换结果表使用只读模型,最多显示 500 行;纯追加使用行插入,保留当前选择。
- 日志/结果、BOM 详情窗口打开时创建,关闭后由 Qt 释放。日志页首次访问时创建;已创建但非活动页不更新文档/结果模型,返回时从纯数据刷新。
- TaskLogPresenter 保存有界日志状态和最多 100 条界面消息;BOM 数据继续按批次保存在原数据层,未保存草稿不依赖详情控件。关闭日志取消在途查询,重开重新读取最新页;初次强制打开不重复发查询。
- 保留分页滚动语义:最新/轮转后到底、上一页到顶、普通追加保留阅读位置或跟随底部。
## 资源与耗时
运行 `python tools/measure_ui_components.py --revision 84d8f9c` 与省略 revision 的当前版本。每版独立进程,各三次,表格 1000 条规则;耗时为中位数。
| 指标 | 修改前 | 修改后 |
| --- | ---: | ---: |
| 规则表首次绑定数据 | 405.44 ms | 0.25 ms |
| 相同规则刷新 | 383.80 ms | 0.02 ms |
| 规则表 QWidget 子控件 | 2018 | 18 |
| 独立 QCheckBox | 1000 | 0 |
| 执行面板未打开详情时的 QWidget 子控件 | 49 | 12 |
以上计时包含 populate 的同步工作,不包含窗口首次绘制、数据库读取或 CAD;控件数量不等同于进程内存。新模型仍保存规则数据,只在可见区域绘制。
原始 JSON:`build/ui-components-20261015/before.json`、`after.json`。复现工具已纳入 Git。
## 验证范围
针对 Qt 生命周期、原生委托勾选/服务持久化、选中保留、分页滚动、关闭期间在途查询、立即重开、切换任务、BOM 校验/批次草稿以及原工作区回归进行验证。
最终针对性回归 **63 passed, 30.72s**,范围为 `test_lazy_components.py`、`test_execution_results_view.py`、`test_ui_responsiveness.py`、`test_ui_workspace.py`、`test_replacement_logs.py`、`test_bom_batch.py`、`test_bom_import_report.py`、`test_ui_remediation.py`。新增资源生命周期用例在修改前观察到 4 项预期失败,修改后通过。只读审查指出的分页滚动和结果追加选择丢失均已修正并覆盖。
使用 `tools/probe_workspace_layout.py` 复制 `build/bom-native-roundtrip-fixed-20261015` 证据数据库复放,输出在 `build/ui-components-layout-20261015`。980×700 实际尺寸保持,位号表 viewport 高 135px;执行、BOM 模板、Value 策略可见;执行结果显示已有真实回读记录;跨批报告隐藏、返回恢复;源数据库 SHA256 不变。检查了结果截图。
本轮未运行真实替换、未启动 CAD、未打包或发布。此前 CAD 原生连接偶发阻塞、千步执行性能问题不属于本轮结论。
@@ -0,0 +1,16 @@
# UI component lifetime implementation plan
**Goal:** Reduce unnecessary UI allocation and hidden-page updates while retaining the existing workflow.
**Architecture:** Reuse the main task workspace. Render rules and results through Qt item models. Keep task logs and BOM report data outside disposable detail dialogs; create views only when opened and render only the active detail tab.
**Constraints:** Remain on the 1.1.2 development branch, preserve BOM/direct editing and batch drafts, do not package or release, do not launch CAD or alter original project/evidence data.
- [x] Establish allocation/timing baseline and failing resource-lifetime regressions.
- [x] Replace per-rule item widgets with QAbstractTableModel/QTableView; keep ordering, rule identity, persisted confirmation, lock gates and selection.
- [x] Extract disposable detail dialogs, lazy-load log tab, retain data independently, invalidate reads on closing and read latest on reopening.
- [x] Migrate UI callers, tests and evidence tools to explicit view/data APIs.
- [x] Verify lifecycle, paging, visible-only rendering, BOM drafts and actual Qt delegate interaction; reproduce UI layout using copied evidence.
- [x] Review changes and record measured results in `docs/reviews/2026-10-15-ui-component-lifetime.md`.
Integration: commit and push these changes on the existing `codex/execution-responsiveness` development branch; no release/tag/package.