c-sharp icon indicating copy to clipboard operation
c-sharp copied to clipboard

CleanupTelemetryData Taking Too Much CPU/Memory

Open Mike-Becatti opened this issue 1 year ago • 0 comments

Code Optimizations in Azure has identified a excessive Memory usage by the "PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData" method. It has 3 recommendations.

Recommendation 1:

Description: A lot of CPU or Memory is being spent in Enumerable<T>.ToDictionary().

Current Condition: 19% of your Memory was spent in Enumerable.ToDictionary called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <2%.

Recommendations: Verify that Enumerable<T>.ToDictionary() isn't being called for a few look-ups in the resulting Dictionary<K, V>. This can instead be accomplished simply by enumerating over the Enumerable<T>.

Recommendation 2:

**Description: ** Task.ScheduleAndStart is causing unusually high memory allocations.

Current Condition: 6% of your Memory was spent in Task.ScheduleAndStart called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <1%.

Recommendations: Consider investigating why Task.ScheduleAndStart is causing higher than expected memory allocations.

Recommendation 3:

**Description: ** Excessive string concatenation is causing lots of allocations and CPU consumption.

Current Condition: 3% of your Memory was spent in String.Concat called from PubnubApi.EndPoint.TelemetryManager.CleanupTelemetryData. We expected this value to be <1%.

Recommendations: Consider using cheaper alternatives such as String.Join or a StringBuilder instead.

Mike-Becatti avatar Apr 02 '24 01:04 Mike-Becatti