Every DefaultPlateFiller.Fill makes a fresh canonical copy of the drawing, and BestFitCache/FillResultCache keyed by drawing reference, so fills never shared results and the static caches grew without bound. CanonicalFrame now records which drawing each canonical copy came from. Both caches key weakly on that source drawing, so every canonical copy shares one entry and released drawings can be collected. An entry is dropped when the drawing's Program instance or canonical angle changes. Best-fit candidates are computed once per (drawing, spacing) through BestFitFinder.FindCandidates and filtered per plate size with the same filter FindBestFits uses. FillResultCache keeps canonical and non-canonical callers apart. Adds Debug-only PerfCounters for best-fit runs, offset perimeter builds and Part.Intersects calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.4 KiB
C#
38 lines
1.4 KiB
C#
using System.Diagnostics;
|
|
using System.Threading;
|
|
|
|
namespace OpenNest
|
|
{
|
|
/// <summary>
|
|
/// Debug-only call counters for the fill hot paths. They confirm that a cache or shortcut
|
|
/// actually removes the work it claims to; Release builds compile the increments away.
|
|
/// </summary>
|
|
public static class PerfCounters
|
|
{
|
|
private static long findBestFits;
|
|
private static long offsetPerimeterEntities;
|
|
private static long partIntersects;
|
|
|
|
public static long FindBestFits => Interlocked.Read(ref findBestFits);
|
|
public static long OffsetPerimeterEntities => Interlocked.Read(ref offsetPerimeterEntities);
|
|
public static long PartIntersects => Interlocked.Read(ref partIntersects);
|
|
|
|
[Conditional("DEBUG")]
|
|
public static void CountFindBestFits() => Interlocked.Increment(ref findBestFits);
|
|
|
|
[Conditional("DEBUG")]
|
|
public static void CountOffsetPerimeterEntities() =>
|
|
Interlocked.Increment(ref offsetPerimeterEntities);
|
|
|
|
[Conditional("DEBUG")]
|
|
public static void CountPartIntersects() => Interlocked.Increment(ref partIntersects);
|
|
|
|
public static void Reset()
|
|
{
|
|
Interlocked.Exchange(ref findBestFits, 0);
|
|
Interlocked.Exchange(ref offsetPerimeterEntities, 0);
|
|
Interlocked.Exchange(ref partIntersects, 0);
|
|
}
|
|
}
|
|
}
|