perf(context)!: release retired fibers and bound diagnostic history
Publish UPM package / publish (push) Successful in 2s
Publish NuGet packages / publish (push) Successful in 1m29s

This commit is contained in:
2026-09-29 10:14:41 +08:00
parent b93f3e6122
commit d3eca1f155
8 changed files with 220 additions and 19 deletions
+16 -3
View File
@@ -14,6 +14,7 @@ namespace ShrinkContext
public sealed class ShrinkCtx
{
private readonly List<ShrinkEffectHandle> _effects = new();
private bool _disposing;
private readonly Dictionary<string, string>? _isolateOverlay;
private Dictionary<string, IReadOnlyDictionary<string, object?>>? _interceptOverlay;
@@ -81,6 +82,13 @@ namespace ShrinkContext
internal void Attach(ShrinkEffectHandle handle) => _effects.Add(handle);
internal void Detach(ShrinkEffectHandle handle)
{
// During parent teardown the reverse traversal owns removal.
if (!_disposing)
_effects.Remove(handle);
}
/// <summary>
/// 前向已在外部执行完毕的效应:仅登记逆操作(供桥接适配器把既有 API 的"注册/注销"对包装为可逆效应)。
/// </summary>
@@ -98,9 +106,14 @@ namespace ShrinkContext
/// <summary>按 LIFO 顺序执行本上下文注册的全部逆操作。</summary>
public async UniTask DisposeAsync()
{
for (var i = _effects.Count - 1; i >= 0; i--)
await _effects[i].DisposeAsync();
_effects.Clear();
_disposing = true;
try
{
for (var i = _effects.Count - 1; i >= 0; i--)
await _effects[i].DisposeAsync();
_effects.Clear();
}
finally { _disposing = false; }
}
// ---------------- 余效应(论文 3.2 / 算法 2) ----------------