fix(driver-twincat): resolve Medium code-review finding (Driver.TwinCAT-012)

GetMemoryFootprint now returns tagsByName * 256 + nativeSubs * 512 bytes
instead of a hard-coded 0; document that the stream-and-discard symbol
browse leaves no flushable cache so FlushOptionalCachesAsync is a
deliberate no-op.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 10:50:28 -04:00
parent 40b28e8820
commit 3f6b61133e
2 changed files with 17 additions and 2 deletions

View File

@@ -134,7 +134,22 @@ public sealed class TwinCATDriver : IDriver, IReadable, IWritable, ITagDiscovery
}
public DriverHealth GetHealth() => _health;
public long GetMemoryFootprint() => 0;
/// <summary>
/// Estimated bytes attributable to this driver instance (Driver.TwinCAT-012).
/// This driver holds no flushable symbol cache — <c>BrowseSymbolsAsync</c> streams and
/// discards; the footprint reflects live allocations only:
/// ~256 bytes per pre-declared tag (tag-definition record + dictionary overhead) and
/// ~512 bytes per active native subscription.
/// </summary>
public long GetMemoryFootprint() =>
(_tagsByName.Count * 256L) + (_nativeSubs.Count * 512L);
/// <summary>
/// No flushable cache exists in this driver — the symbol table is streamed fresh on
/// every <see cref="DiscoverAsync"/> call. This is a no-op but is deliberately present
/// so Core's cache-budget enforcement sees a compliant Tier-A driver.
/// </summary>
public Task FlushOptionalCachesAsync(CancellationToken cancellationToken) => Task.CompletedTask;
internal int DeviceCount => _devices.Count;