perf(diag): per-frame history export + checkpoint LOH/cache counters + soak capped mode (2026-07-24 audit review)
An adversarial performance review found our own instruments cannot measure the project's own performance gates: - FrameProfiler aggregated CPU/GPU/alloc/stage samples into ~5-second windows and reset the ring buffers after each report, so route-wide p50/p95/p99 distributions across a whole soak could not be reconstructed after the fact. ACDREAM_FRAME_HISTORY=<path> now opts into a separate per-frame history (one record per frame, ~72 bytes/record, accumulated in memory with zero frame-thread I/O) that a shutdown-only Dispose() writes as CSV. The aggregated [frame-prof] report format and its existing metrics are unchanged. - The canonical checkpoint JSON tracked cache residency (entry/byte counts) but never LOH size/fragmentation, process-wide allocated bytes, or cache hit/miss/eviction traffic — a committed audit JSON showed 65% LOH fragmentation that no tracked instrument recorded, and "does a revisit portal hit or miss the caches" was unanswerable from an artifact alone. WorldLifecycleResourceSnapshot now carries loh_size_bytes/loh_fragmentation_bytes (GCMemoryInfo.GenerationInfo index 3), process_total_allocated_bytes (GC.GetTotalAllocatedBytes), and Interlocked hit/miss/eviction counters for the CPU mesh cache, decoded-texture cache, and the four bounded DAT-object caches (portal/cell/highRes/language, aggregated). - run-connected-r6-soak.ps1 unconditionally forced ACDREAM_UNCAPPED_RENDER=1 with no capped mode, while its sibling lifecycle-gate script correctly gated it behind a switch. Added -Uncapped (default capped, matching the sibling script's pattern), fixed the stationary dwell (12s -> 26s, past the 25s LiveEntityLivenessController deadline the adjacent comment already cited), and now write an env-disclosure.json into the automation artifact directory before every launch listing every ACDREAM_* var the script sets plus -Uncapped, since the prior audit could only see ACDREAM_DUMP_MOVE_TRUTH and nothing else was ever recorded anywhere. Cache counters are wired via the existing composition path (ObjectMeshManager already owns the CPU mesh cache and the mesh extractor directly; content.Dats is threaded into WorldLifecycleResourceSnapshotSource the same way every other composition consumer receives it). The DAT-object cache lives behind IDatReaderWriter, a third-party interface from the DatReaderWriter package that cannot be extended; RuntimeDatCollection (the one production implementation) exposes the aggregate stats directly and a pattern match reads them, degrading to zero for any test double — no new static registry was introduced (GpuMemoryTracker remains the one precedented process-wide static). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> (cherry picked from commit 1da2c33c875b41fa383dd79694ee2765f0e21896)
This commit is contained in:
parent
bfc5e47365
commit
7b456b49d6
20 changed files with 477 additions and 9 deletions
|
|
@ -1,6 +1,7 @@
|
|||
using DatReaderWriter.DBObjs;
|
||||
using DatReaderWriter.Lib.IO;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Threading;
|
||||
|
||||
namespace AcDream.Content;
|
||||
|
||||
|
|
@ -42,6 +43,19 @@ internal sealed class BoundedDatObjectCache
|
|||
private readonly object _gate = new();
|
||||
private long _estimatedBytes;
|
||||
|
||||
// Hit/miss/eviction traffic counters (2026-07-24 measurement-tooling
|
||||
// review). Read via Stats without the _gate lock, so plain fields with
|
||||
// Interlocked increments rather than lock-protected longs.
|
||||
private long _hits;
|
||||
private long _misses;
|
||||
private long _evictions;
|
||||
|
||||
/// <summary>Cumulative hit/miss/eviction counts since construction.</summary>
|
||||
internal CacheStats Stats => new(
|
||||
Interlocked.Read(ref _hits),
|
||||
Interlocked.Read(ref _misses),
|
||||
Interlocked.Read(ref _evictions));
|
||||
|
||||
internal BoundedDatObjectCache(
|
||||
int entryLimit = DefaultEntryLimit,
|
||||
long estimatedByteLimit = DefaultEstimatedByteLimit,
|
||||
|
|
@ -80,10 +94,12 @@ internal sealed class BoundedDatObjectCache
|
|||
{
|
||||
if (!_byKey.TryGetValue(new CacheKey(typeof(T), fileId), out var node))
|
||||
{
|
||||
Interlocked.Increment(ref _misses);
|
||||
value = default;
|
||||
return false;
|
||||
}
|
||||
|
||||
Interlocked.Increment(ref _hits);
|
||||
MarkMostRecentlyUsed(node);
|
||||
value = (T)node.Value.Value;
|
||||
return true;
|
||||
|
|
@ -146,6 +162,7 @@ internal sealed class BoundedDatObjectCache
|
|||
_leastRecentlyUsed.RemoveFirst();
|
||||
_byKey.Remove(node.Value.Key);
|
||||
_estimatedBytes -= node.Value.EstimatedBytes;
|
||||
Interlocked.Increment(ref _evictions);
|
||||
}
|
||||
|
||||
private static long EstimateRetainedBytes(IDBObj value)
|
||||
|
|
|
|||
18
src/AcDream.Content/CacheStats.cs
Normal file
18
src/AcDream.Content/CacheStats.cs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
namespace AcDream.Content;
|
||||
|
||||
/// <summary>
|
||||
/// Hit/miss/eviction counters for one bounded content cache. 2026-07-24
|
||||
/// measurement-tooling review: the canonical checkpoint JSON tracked cache
|
||||
/// residency (entry/byte counts) but never hit/miss traffic, so "does a
|
||||
/// revisit portal hit or miss the caches" was unanswerable from the
|
||||
/// artifact alone. Each cache accumulates its own counts via
|
||||
/// <see cref="System.Threading.Interlocked"/> — mesh preparation runs on up
|
||||
/// to four concurrent workers — and exposes them through this public,
|
||||
/// cross-assembly-safe struct so <c>AcDream.App</c> diagnostics can read
|
||||
/// them without taking the cache's internal lock.
|
||||
/// </summary>
|
||||
public readonly record struct CacheStats(long Hits, long Misses, long Evictions)
|
||||
{
|
||||
public static CacheStats operator +(CacheStats a, CacheStats b) =>
|
||||
new(a.Hits + b.Hits, a.Misses + b.Misses, a.Evictions + b.Evictions);
|
||||
}
|
||||
|
|
@ -56,6 +56,16 @@ public sealed class DatCollectionAdapter : IDatReaderWriter {
|
|||
/// <summary>Source directory of the underlying DatCollection.</summary>
|
||||
public string SourceDirectory => _dats.Options.DatDirectory ?? string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Aggregate hit/miss/eviction counts across the four bounded per-database
|
||||
/// object caches (portal/cell/highRes/language). 2026-07-24
|
||||
/// measurement-tooling review: answers "do revisit portals hit or miss
|
||||
/// the caches" for the DAT-object layer specifically.
|
||||
/// </summary>
|
||||
public CacheStats ObjectCacheStats =>
|
||||
_portal.ObjectCacheStats + _cell.ObjectCacheStats
|
||||
+ _highRes.ObjectCacheStats + _language.ObjectCacheStats;
|
||||
|
||||
public IDatDatabase Portal => _portal;
|
||||
public IDatDatabase Cell => _cell;
|
||||
public ReadOnlyDictionary<uint, IDatDatabase> CellRegions => _cellRegions;
|
||||
|
|
@ -173,6 +183,9 @@ public sealed class DatDatabaseWrapper : IDatDatabase {
|
|||
public DatDatabase Db => _db;
|
||||
public int Iteration => _db.Iteration?.CurrentIteration ?? 0;
|
||||
|
||||
/// <summary>This database's bounded DAT-object cache hit/miss/eviction counts (2026-07-24 measurement-tooling review).</summary>
|
||||
public CacheStats ObjectCacheStats => _cache.Stats;
|
||||
|
||||
public IEnumerable<uint> GetAllIdsOfType<T>() where T : IDBObj =>
|
||||
_db.GetAllIdsOfType<T>();
|
||||
|
||||
|
|
|
|||
|
|
@ -21,6 +21,19 @@ internal sealed class DecodedTextureCache {
|
|||
private readonly int _maximumEntries;
|
||||
private long _residentBytes;
|
||||
|
||||
// Hit/miss/eviction traffic counters (2026-07-24 measurement-tooling
|
||||
// review). Read via Stats without the _gate lock, so plain fields with
|
||||
// Interlocked increments rather than lock-protected longs.
|
||||
private long _hits;
|
||||
private long _misses;
|
||||
private long _evictions;
|
||||
|
||||
/// <summary>Cumulative hit/miss/eviction counts since construction.</summary>
|
||||
public CacheStats Stats => new(
|
||||
Interlocked.Read(ref _hits),
|
||||
Interlocked.Read(ref _misses),
|
||||
Interlocked.Read(ref _evictions));
|
||||
|
||||
public DecodedTextureCache(long maximumBytes, int maximumEntries) {
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(maximumBytes);
|
||||
ArgumentOutOfRangeException.ThrowIfNegative(maximumEntries);
|
||||
|
|
@ -47,10 +60,12 @@ internal sealed class DecodedTextureCache {
|
|||
public bool TryGet(DecodedTextureKey key, out byte[] pixels) {
|
||||
lock (_gate) {
|
||||
if (!_entries.TryGetValue(key, out var node)) {
|
||||
Interlocked.Increment(ref _misses);
|
||||
pixels = null!;
|
||||
return false;
|
||||
}
|
||||
|
||||
Interlocked.Increment(ref _hits);
|
||||
Touch(node);
|
||||
pixels = node.Value.Pixels;
|
||||
return true;
|
||||
|
|
@ -131,6 +146,7 @@ internal sealed class DecodedTextureCache {
|
|||
_lru.Remove(node);
|
||||
_entries.Remove(node.Value.Key);
|
||||
_residentBytes -= node.Value.Pixels.LongLength;
|
||||
Interlocked.Increment(ref _evictions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,9 @@ public sealed class MeshExtractor {
|
|||
// by up to MaxParallelLoads (4) decode workers.
|
||||
private readonly System.Collections.Concurrent.ConcurrentDictionary<uint, byte[]> _solidColorTextureCache = new();
|
||||
|
||||
/// <summary>Decoded-texture cache hit/miss/eviction counts (2026-07-24 measurement-tooling review).</summary>
|
||||
public CacheStats DecodedTextureCacheStats => _decodedTextureCache.Stats;
|
||||
|
||||
/// <summary>
|
||||
/// MP1a mechanical seam: receives particle-preload meshes staged
|
||||
/// mid-extraction (see <see cref="CollectEmittersFromScript"/>). The App
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue