Measuring Finalized Objects
06/25/2021
This a quick post on how to measure the number of finalized objects with PerfView and WinDBG. The reason to measured this is because many appliciations use thousands of objects with finalizers. As finalization may not been suppressed on these objects, it can cause a significant performance degradation, which does not show up on tail latency, but only on throughput tests. Focusing only on a single operation only, can easily hide such an issue.
Even today I seem to run into libraries / code paths that excessively use objects with finalizers. .NET runtime's garbage collector handles finalizable objects separately from other objects. Housekeeping for live finalizable objects requires more resouces compared to non-finalizable ojects. Cleaning up dead finalizable objects requires even more resouces, including to run the Finalizer method, which is eventually user code.
When finalizers are combined with the dispose pattern, one should call GC.SuppressFinalize
to exempt the objects from finalization. Thus saving the resoucers otherwise required for the cleanup. Although allocating objects with finalizers are still slower to regular objects.