体积 L3(-fno-exceptions + MemProbe + LTO)与 L1 几何产物层;产物 909,824 -> 788,992 B
## 为什么
用户 2026-10-29 要求:按既定计划完整实现改进,但
① **不得把编译产物拆成 DLL**(项目定位是单文件轻量工具,最终只能有一个 .exe);
② 异常处理改用**预检验**而不是 try/catch(-fno-exceptions 省体积,且 try/catch 本身开销大);
③ 先删除 Documents 内三份 UI 重构文档再按"计划 / 当前进度 / 最终报告"重建;
④ 顺便审计代码,删除无用/过时注释,修复名实不符;
⑤ 提交到本地仓库,期间不要占用用户的鼠标/键盘/屏幕。
## 改了什么
### 1. 体积(909,824 B -> 788,992 B,-120,832 B,-13.3%)
Makefile 新增三个可覆盖开关(默认全为 1):
- `LAYOUT_BOUNDS` 编入/剔除「显示布局边界」叠加层
- `NO_EXCEPTIONS` 追加 `-fno-exceptions`
- `LTO` 追加 `-flto`(编译 + 链接)
派生:`FUNC_SECTIONS`(LTO 下为空)、`GC_SECTIONS`(`-Wl,--gc-sections`)、
`ASM_LISTING`/`ASM_LISTING_C`(LTO 下为空,因为 lto-wrapper 会丢弃 `-Wa` 清单)。
两个实测复现的坑(已写进 Makefile 注释):
- **切换 LTO 必须 `make clean`**:LTO 与非 LTO 目标文件混链会让 GCC 15.2.0 在
`binds_to_current_def_p (symtab.cc:2598)` 处 ICE。
- **`-flto` 与 `-ffunction-sections -fdata-sections` 同时打开也 ICE**(干净重编也必崩,
报错落点是 `DataModel.hpp:393`,但那是 COMDAT 解析落点、不是原因)⇒
LTO 下 `FUNC_SECTIONS` 置空,并加 `-flto-partition=one`:默认 11 个分区的 LTRANS
稳定复现,单分区从未复现。**这是稳定性选项,不是性能选项。**
### 2. 关异常必须成对交付:预检验 + 兜底
新增 `Utilities/Inc/MemProbe.hpp` + `Utilities/Src/MemProbe.cpp`:
- `MemAvailablePhysical()`:`GlobalMemoryStatusEx` + 200ms 缓存
- `MemCanAllocate(bytes)`:预留后仍须保有 1/8 可用内存
- `MemReserveIfRoom(container, n)`:含 `capacity()` 早退与乘法溢出保护
- `MemInstallTerminateHandler()`:OOM 时弹一次带建议的模态提示后 `_Exit`(而不是静默消失)
接入:
- `Utilities/Src/DataModel.cpp`:全仓**唯一**的 `try/catch`(`extremes.reserve` 捕
`std::bad_alloc`)改为 `MemReserveIfRoom(extremes, count / 8)`
- `Components/PlotView/Src/PlotView.cpp`:`AvailablePhysicalBytes()` 原有一份**完整重复**
的 `GlobalMemoryStatusEx` + 缓存实现 → 转发 `MemAvailablePhysical()`
- `Components/Application/Src/Application.cpp`:`Initialize()` 开头安装 terminate handler
### 3. L1 几何产物层
新增 `Components/Shared/Inc/UiBox.hpp` + `Src/UiBox.cpp`:
- `struct UiBox { rect, clip, depth, layer }` —— 纯值类型,不继承任何东西
(继承会和 PlotView 4 层位图缓存 / SignalPanel 行位图缓存的失效体系打架)
- `class UiBoxTable : public UiTextRectSink` —— 只累计几何 + 裁剪/层/遮挡,**不含绘制代码**
`UiComponent::CollectDebugBoxes` → **`virtual void BuildBoxes(UiBoxTable&)`**:
组件从"收集布局边界(调试用)"改为"上报几何产物",不再需要知道"调试"这个概念存在。
`UiDebugBounds.hpp/.cpp` 退化为唯一的消费者(配色 + 包角描边 + 遮挡挖洞)。
除宿主 `ApplicationCommands.cpp` 外,所有组件源码现在只包含 `UiBox.hpp`。
### 4. 审计
- `MemProbe` 里"省 40~60KB"的估算 → 改为实测 27,136 B
- `MemProbe.hpp` 的 `<new>`、`MemProbe.cpp` 的 `<cstdio>`:未使用,删除
- `UiDebugPaintBounds(g, rect, depth)`:零调用者,删除(只保留带 clip 的版本)
- `TabBar`/`Toolbar`/`PlotView`/`SignalPanel` 的 `BuildBoxes` 文档"(调试用)"→"几何 box"
- `PlotView::SetForceFullRepaint` 补写"为什么保留而不优化"
### 5. 文档
`Documents/UI_Refactor_Plan.md` / `_Progress.md` / `_Report.md` 先 `git rm` 再按
「计划 / 当前进度 / 最终报告」重建;`Documents/agent_mem.md` 追加第十三轮记录。
## 怎么验证
```
make clean
make release TARGET_FILE_NAME=JustDataInspector -j16 # 零 error / 零 warning,788,992 B
make debug TARGET_FILE_NAME=JustDataInspectorD -j16 # 零 warning
uicheck 69/69 lbcheck 21/21 lbresid 5/5 lbzorder 4/4 lbcovr 7/7 lbpanel 10/10
rendercheck: 8 个场景哈希与改造前逐一相同 + FUNC 7/7 PASS, exit=0
A FAED59DF284153DB B E6443BFE4E3955F8 C 96A0AA8C402F1729 D E3D5DBD998E43720
E DA0583CB13C26A6F F FFB822159F604D1D G 19F8DE8FE3A8DF18 H DBBDDE4CB2C97C92
```
体积溯源(`objdump -h`,基线 → 最终):
`.text` 735,600 → 657,168;`.rdata` 49,184 → 35,016;
`.xdata` 48,132 → 27,512;`.pdata` 35,424 → 28,524;`.rsrc` 20,656 不变。
## 没做什么(有意为之)
- **没有拆 DLL**(用户明确要求单文件)
- **没有改优化等级**(`-Oz` 保持)
- **L2(`UiDamage` 脏矩形 + 独立叠加层)评估后缓做**:受益方只有"调试开关打开时的帧率",
而正确实现必须把叠加层旧矩形注入底层组件重绘范围,穿透 PlotView 四条快路径 + 两层缓存;
在用户反复报过"拖拽错位 / 贴图残留"的背景下,风险与收益不成比例。理由写在
`Documents/UI_Refactor_Plan.md` §5 与 `PlotView::SetForceFullRepaint` 的文档里。
This commit is contained in:
1 parent
739a523af5
commit
044b87383b
34 files changed
+1117
-2200
No files matched your search
@@ -1,7 +1,7 @@
|
||||
#include "ColorPickerPopup.hpp"
|
||||
|
||||
#include "UiControls.hpp"
|
||||
#include "UiDebugBounds.hpp"
|
||||
#include "UiBox.hpp"
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <cstdlib>
|
||||
@@ -1094,7 +1094,7 @@ namespace jdi
|
||||
}
|
||||
}
|
||||
|
||||
void ColorPickerPopup::CollectDebugBoxes(UiDebugBoxList& boxes) const
|
||||
void ColorPickerPopup::BuildBoxes(UiBoxTable& boxes) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
#include "PopupMenuInternal.hpp"
|
||||
#include "UiControls.hpp"
|
||||
#include "UiDebugBounds.hpp"
|
||||
#include "UiBox.hpp"
|
||||
#include "UiLayout.hpp"
|
||||
|
||||
namespace jdi
|
||||
@@ -706,7 +706,7 @@ namespace jdi
|
||||
}
|
||||
|
||||
|
||||
void PopupMenu::CollectDebugBoxes(UiDebugBoxList& boxes) const
|
||||
void PopupMenu::BuildBoxes(UiBoxTable& boxes) const
|
||||
{
|
||||
if (!m_open)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
#include "UiBox.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
void UiBoxTable::Clear()
|
||||
{
|
||||
m_boxes.clear();
|
||||
m_occluders.clear();
|
||||
m_layer = 0;
|
||||
m_clip = gd::RectF();
|
||||
}
|
||||
|
||||
void UiBoxTable::OnTextRect(const gd::RectF& rect)
|
||||
{
|
||||
// 文本用固定层级 4:它总是"最里层"的元素(复选框里的字、行里的信号名…)。
|
||||
Add(rect, 4);
|
||||
}
|
||||
|
||||
void UiBoxTable::Add(const gd::RectF& rect, int depth)
|
||||
{
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return; // 空矩形(未布局 / 该元素当前不显示)不登记。
|
||||
}
|
||||
if (m_clip.Width > 0.0f && m_clip.Height > 0.0f)
|
||||
{
|
||||
// 与所属组件的区域无交集 ⇒ 已经完全滚出地盘,不必登记(也避免越界登记到邻居的地盘上)。
|
||||
if (rect.X + rect.Width <= m_clip.X || rect.X >= m_clip.X + m_clip.Width ||
|
||||
rect.Y + rect.Height <= m_clip.Y || rect.Y >= m_clip.Y + m_clip.Height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
UiBox box;
|
||||
box.rect = rect;
|
||||
box.clip = m_clip;
|
||||
box.depth = (depth < 0) ? 0 : depth;
|
||||
box.layer = m_layer;
|
||||
m_boxes.push_back(box);
|
||||
}
|
||||
|
||||
void UiBoxTable::AddAll(const std::vector<gd::RectF>& rects, int depth)
|
||||
{
|
||||
for (const gd::RectF& rect : rects)
|
||||
{
|
||||
Add(rect, depth);
|
||||
}
|
||||
}
|
||||
|
||||
void UiBoxTable::AddOccluder(const gd::RectF& rect)
|
||||
{
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Occluder occluder;
|
||||
occluder.rect = rect;
|
||||
occluder.layer = m_layer;
|
||||
m_occluders.push_back(occluder);
|
||||
}
|
||||
|
||||
} // namespace jdi
|
||||
@@ -1,13 +1,13 @@
|
||||
#include "UiComponent.hpp"
|
||||
|
||||
#include "UiDebugBounds.hpp"
|
||||
#include "UiBox.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
|
||||
// 默认实现放在 .cpp 而不是头文件内联:`UiComponent.hpp` 是四个大组件都要包含的
|
||||
// 公共头,不应把 `UiDebugBounds.hpp`(box 收集器)也拉进它们的编译单元。
|
||||
void UiComponent::CollectDebugBoxes(UiDebugBoxList& boxes)
|
||||
// 公共头,不应把 `UiBox.hpp`(几何收集器)也拉进它们的编译单元。
|
||||
void UiComponent::BuildBoxes(UiBoxTable& boxes)
|
||||
{
|
||||
boxes.Add(Area(), 0);
|
||||
}
|
||||
|
||||
@@ -77,63 +77,6 @@ namespace jdi
|
||||
}
|
||||
} // namespace
|
||||
|
||||
void UiDebugBoxList::Clear()
|
||||
{
|
||||
m_boxes.clear();
|
||||
m_occluders.clear();
|
||||
m_layer = 0;
|
||||
m_clip = gd::RectF();
|
||||
}
|
||||
|
||||
void UiDebugBoxList::OnTextRect(const gd::RectF& rect)
|
||||
{
|
||||
// 文本用固定层级 4:它总是"最里层"的元素(复选框里的字、行里的信号名…)。
|
||||
Add(rect, 4);
|
||||
}
|
||||
|
||||
void UiDebugBoxList::Add(const gd::RectF& rect, int depth)
|
||||
{
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return; // 空矩形(未布局 / 该元素当前不显示)不登记。
|
||||
}
|
||||
if (m_clip.Width > 0.0f && m_clip.Height > 0.0f)
|
||||
{
|
||||
// 与所属组件的区域无交集 ⇒ 已经完全滚出地盘,不必登记(也避免越界画到邻居上)。
|
||||
if (rect.X + rect.Width <= m_clip.X || rect.X >= m_clip.X + m_clip.Width ||
|
||||
rect.Y + rect.Height <= m_clip.Y || rect.Y >= m_clip.Y + m_clip.Height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
UiDebugBox box;
|
||||
box.rect = rect;
|
||||
box.clip = m_clip;
|
||||
box.depth = (depth < 0) ? 0 : depth;
|
||||
box.layer = m_layer;
|
||||
m_boxes.push_back(box);
|
||||
}
|
||||
|
||||
void UiDebugBoxList::AddAll(const std::vector<gd::RectF>& rects, int depth)
|
||||
{
|
||||
for (const gd::RectF& rect : rects)
|
||||
{
|
||||
Add(rect, depth);
|
||||
}
|
||||
}
|
||||
|
||||
void UiDebugBoxList::AddOccluder(const gd::RectF& rect)
|
||||
{
|
||||
if (!(rect.Width > 0.0f) || !(rect.Height > 0.0f))
|
||||
{
|
||||
return;
|
||||
}
|
||||
Occluder occluder;
|
||||
occluder.rect = rect;
|
||||
occluder.layer = m_layer;
|
||||
m_occluders.push_back(occluder);
|
||||
}
|
||||
|
||||
std::uint32_t UiDebugBoundsColor(int depth)
|
||||
{
|
||||
// 与主题无关的固定配色:调试层必须"永远显眼",不能跟随用户主题变成接近底色。
|
||||
@@ -152,11 +95,6 @@ namespace jdi
|
||||
}
|
||||
}
|
||||
|
||||
void UiDebugPaintBounds(gd::Graphics& g, const gd::RectF& rect, int depth)
|
||||
{
|
||||
UiDebugPaintBoundsClipped(g, rect, gd::RectF(), depth);
|
||||
}
|
||||
|
||||
void UiDebugPaintBoundsClipped(gd::Graphics& g, const gd::RectF& rect, const gd::RectF& clip,
|
||||
int depth)
|
||||
{
|
||||
@@ -174,7 +112,7 @@ namespace jdi
|
||||
return;
|
||||
}
|
||||
|
||||
// ⚠️ 与裁剪矩形求交(见 `UiDebugBoxList::SetClip`):组件内部的元素可能落在地盘之外。
|
||||
// ⚠️ 与裁剪矩形求交(见 `UiBoxTable::SetClip`):组件内部的元素可能落在地盘之外。
|
||||
// 用 floor/ceil 而不是取整:裁剪是"能看见多少就画多少",宁可多一像素也不要把
|
||||
// 紧贴边界的包角整个裁掉。
|
||||
if (clip.Width > 0.0f && clip.Height > 0.0f)
|
||||
@@ -240,7 +178,7 @@ namespace jdi
|
||||
g.Restore(state);
|
||||
}
|
||||
|
||||
void UiDebugPaintBoxList(gd::Graphics& g, const UiDebugBoxList& boxes)
|
||||
void UiDebugPaintBoxList(gd::Graphics& g, const UiBoxTable& boxes)
|
||||
{
|
||||
if (boxes.Empty())
|
||||
{
|
||||
@@ -251,14 +189,14 @@ namespace jdi
|
||||
// * `layer` 保证"后收集的(更靠上的浮层)压住先收集的" —— 没有它,信号面板的行边界
|
||||
// 会盖在右键弹出的二级菜单上面;
|
||||
// * `depth` 保证同一层内先画父再画子,子元素的彩色包角不会被父的边压住。
|
||||
std::vector<const UiDebugBox*> ordered;
|
||||
std::vector<const UiBox*> ordered;
|
||||
ordered.reserve(boxes.Count());
|
||||
for (const UiDebugBox& box : boxes.Items())
|
||||
for (const UiBox& box : boxes.Items())
|
||||
{
|
||||
ordered.push_back(&box);
|
||||
}
|
||||
std::stable_sort(ordered.begin(), ordered.end(),
|
||||
[](const UiDebugBox* lhs, const UiDebugBox* rhs)
|
||||
[](const UiBox* lhs, const UiBox* rhs)
|
||||
{
|
||||
if (lhs->layer != rhs->layer)
|
||||
{
|
||||
@@ -267,14 +205,14 @@ namespace jdi
|
||||
return lhs->depth < rhs->depth;
|
||||
});
|
||||
|
||||
for (const UiDebugBox* box : ordered)
|
||||
for (const UiBox* box : ordered)
|
||||
{
|
||||
// ⚠️ 遮挡:浮层(菜单 / 拾色器)是不透明的,它上面的内容不该出现下层组件的边框线。
|
||||
// 仅靠 layer 排序只能决定"两个 box 重叠时谁压谁",不能阻止"先画的线仍然可见",
|
||||
// 因此这里把**更高层**的遮挡矩形从裁剪区里排除。
|
||||
gd::Region region;
|
||||
bool occluded = false;
|
||||
for (const UiDebugBoxList::Occluder& occluder : boxes.Occluders())
|
||||
for (const UiBoxTable::Occluder& occluder : boxes.Occluders())
|
||||
{
|
||||
if (occluder.layer <= box->layer)
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include "UiDebugBounds.hpp"
|
||||
#include "UiBox.hpp"
|
||||
|
||||
namespace jdi
|
||||
{
|
||||
@@ -255,7 +255,7 @@ namespace jdi
|
||||
return UiRectHasArea(TakeDirty());
|
||||
}
|
||||
|
||||
void UiWidget::CollectDebugBoxes(UiDebugBoxList& boxes, int depth) const
|
||||
void UiWidget::BuildBoxes(UiBoxTable& boxes, int depth) const
|
||||
{
|
||||
if (!m_visible || !UiRectHasArea(m_bounds))
|
||||
{
|
||||
@@ -270,7 +270,7 @@ namespace jdi
|
||||
{
|
||||
if (child != nullptr)
|
||||
{
|
||||
child->CollectDebugBoxes(boxes, depth + 1);
|
||||
child->BuildBoxes(boxes, depth + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user