mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-23 09:48:48 +08:00
Card Performance Notes
Scope
本轮补充 Card 动态集合同步路径:
Card.Actions -> CardActionPanel.ActionsCardActionPanel.Actions -> UniformGrid.ChildrenCardTabsContent.Items -> TabControl.Items
Root Cause
NotifyCollectionChangedEventArgs.NewItems/OldItems原先通过OfType<Control>()传入InsertRange/RemoveAll,每个 add/remove 分支都会创建 LINQ 类型过滤迭代器。- Avalonia
AvaloniaList.InsertRange对IList有快路径;传入 LINQ iterator 会落到枚举器路径。参考.referenceprojects/Avalonia/src/Avalonia.Base/Collections/AvaloniaList.cs:343-427。 - Avalonia
AvaloniaList.RemoveAll会先把传入 enumerable 建成HashSet<T>,再扫描目标集合。参考.referenceprojects/Avalonia/src/Avalonia.Base/Collections/AvaloniaList.cs:530-550。镜像集合 remove 已有OldStartingIndex和OldItems.Count,按 range 删除更直接,也避免重复元素时的过删风险。 CardTabsContent的 move 分支原先把OldStartingIndex当作OldItems的起始下标使用,oldIndex > OldItems.Count时不会收集/删除任何移动项。
Changes
- 新增共享
ControlCollectionChangedUtils,add 路径先用IList.Count/indexer收集Control列表,再交给InsertRange的IList快路径。 Card/CardActionPanelremove 路径改为RemoveRange(OldStartingIndex, OldItems.Count)。CardTabsContentadd/remove 去掉OfType<Control>();move 分支改为按OldItems.Count删除并按 AvaloniaMoveRange的新索引语义插回。
Benefit
这轮是结构性收益:Card 动态 actions / tabs 同步时少走 LINQ 类型过滤和 HashSet remove 扫描;同时修复 tabs 批量 move 的边界错误。不声明本轮页面加载耗时提升。
| Metric | Baseline | Optimized | Formula | Improvement | Conclusion |
|---|---|---|---|---|---|
Card collection sync OfType<Control> callsites |
6 | 0 | (6 - 0) / 6 |
100.00% | 有效;actions、action panel、tabs add/remove 均去掉 LINQ 类型过滤 |
| Mirrored action remove target scans | 2 scans | 0 scans | (2 - 0) / 2 |
100.00% | 有效;两层 action mirror 均按 OldStartingIndex 删除 |
| CardTabsContent remove value lookups | N lookups | 0 lookups | (N - 0) / N |
100.00% | 有效;tabs remove 改为固定下标 RemoveAt |
| CardTabsContent move stale branch risk | 1 risky branch | 0 risky branches | (1 - 0) / 1 |
100.00% | 正确性修复;按 OldItems.Count 处理移动项 |
| Page-load timing claim | none | none | n/a | n/a | 本轮没有有效前后 timing,不声明页面级速度收益 |
Verification
dotnet build -c Release -f net10.0 --no-restore tools/performances/AtomUI.Performance/AtomUI.Performance.csprojpassed.--verify-card-states当前仍受旧动态模板期望断言影响,不能作为本轮集合同步路径的通过证明。