Skip to content

Lazily Instantiate ConcurrentDictionaries to improve performance #934

@cijothomas

Description

@cijothomas

In TelemetryContext, and in auto-generated constructors of each base telemetry item, ConcurrentDictionaries are created for each telemetry item creation. This is a perf hit as ConcurrentDictionaries are expensive to create, and in most cases, the item is sampled out, so this ConccurentDictionary allocation is wasted.

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/DataContracts/TelemetryContext.cs#L42

https://github.com/Microsoft/ApplicationInsights-dotnet/blob/develop/src/Microsoft.ApplicationInsights/Extensibility/Implementation/External/AvailabilityData_types.cs#L97

Proposal is to make the ConcurrentDictionary creation lazy, and improve performance.

Version Info

SDK Version :
.NET Version :
How Application was onboarded with SDK(VisualStudio/StatusMonitor/Azure Extension) :
OS :
Hosting Info (IIS/Azure WebApps/ etc) :

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions