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

+1 -1
View File
@@ -99,7 +99,7 @@ def measure(root, app):
window._show_task_log()
pump(app, lambda: not window._log_presenter.query.busy)
result['async_recent_log_visible_ms'] = round((time.perf_counter()-start)*1000, 3)
assert 'R39999' in window.run_panel.log_view.toPlainText()
assert 'R39999' in window._log_presenter.log_text
window.close()
QThreadPool.globalInstance().waitForDone()
store.close()
+70
View File
@@ -0,0 +1,70 @@
"""Measure rule-table allocation/refresh and unopened detail controls, without CAD."""
import argparse
import json
import os
from pathlib import Path
from statistics import median
import subprocess
import sys
from time import perf_counter
from types import ModuleType, SimpleNamespace
os.environ.setdefault('QT_QPA_PLATFORM', 'offscreen')
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'src'))
from PySide6.QtCore import QCoreApplication, QEvent
from PySide6.QtWidgets import QApplication, QCheckBox, QWidget
def load_class(module, name, revision):
if revision:
source = subprocess.check_output(
['git', 'show', f'{revision}:src/dx_productivity/trial_task_center/ui/{module}.py'],
encoding='utf-8')
namespace = ModuleType(module)
exec(compile(source, f'{revision}/{module}.py', 'exec'), namespace.__dict__)
return getattr(namespace, name)
import importlib
return getattr(importlib.import_module(f'dx_productivity.trial_task_center.ui.{module}'), name)
def main():
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--revision', help='Baseline Git revision; omit to measure workspace')
parser.add_argument('--output', type=Path)
args = parser.parse_args()
app = QApplication([])
mapping = load_class('mapping_table', 'MappingTable', args.revision)
panel_type = load_class('run_panel', 'RunPanel', args.revision)
rules = tuple(SimpleNamespace(rule_id=str(i), old_part_number=f'OLD{i}', new_part_number='NEW',
custom_value_enabled=False, sync_nc=True, enabled=True, position=i) for i in range(1000))
samples = []
for _ in range(3):
table = mapping()
started = perf_counter()
table.populate(rules)
first = perf_counter() - started
widgets = len(table.findChildren(QWidget))
checkboxes = len(table.findChildren(QCheckBox))
started = perf_counter()
table.populate(rules)
refresh = perf_counter() - started
samples.append((first, refresh))
table.deleteLater()
QCoreApplication.sendPostedEvents(None, QEvent.Type.DeferredDelete)
panel = panel_type()
result = dict(revision=args.revision or 'workspace', rules=len(rules), samples=3,
first_ms=median(s[0] for s in samples) * 1000,
unchanged_refresh_ms=median(s[1] for s in samples) * 1000,
table_widgets=widgets, checkbox_widgets=checkboxes,
unopened_run_panel_widgets=len(panel.findChildren(QWidget)))
text = json.dumps(result, ensure_ascii=False, indent=2)
if args.output:
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(text + '\n', encoding='utf-8')
print(text)
panel.close()
if __name__ == '__main__':
main()
+3 -3
View File
@@ -83,11 +83,11 @@ try:
store.bind_project_task(other.task_id, project.project_id, 'ui-review-separate-batch', 0)
window.run_panel.log_dialog.grab().save(str(output / '04-execution-results.png'))
window.plan_panel.report_dialog.grab().save(str(output / '05-bom-validation-details.png'))
report['result_rows'] = window.run_panel.result_view.rowCount()
before_text = window.plan_panel.bom_report.toPlainText()
report['result_rows'] = window.run_panel.log_dialog.result_view.model().rowCount()
before_text = window.plan_panel.report_text
window.open_task(other.task_id)
idle()
report['bom_report_cross_batch'] = {'current_task': window.plan_panel.task_id, 'expected_other_task': other.task_id, 'visible': window.plan_panel.bom_report.isVisible(), 'retained_previous_text': window.plan_panel.bom_report.toPlainText() == before_text, 'contains_previous_project': 'Audio_D2128' in window.plan_panel.bom_report.toPlainText()}
report['bom_report_cross_batch'] = {'current_task': window.plan_panel.task_id, 'expected_other_task': other.task_id, 'visible': bool(window.plan_panel.report_dialog and window.plan_panel.report_dialog.isVisible()), 'retained_previous_text': window.plan_panel.report_text == before_text, 'contains_previous_project': 'Audio_D2128' in window.plan_panel.report_text}
window.resize(1280, 880)
app.processEvents()
window.grab().save(str(output / '03-other-batch-report-hidden.png'))