Skip to content

Avoid ConcurrentDictionary allocation in DisposeObjectsBeforeLosingScope#54127

Open
Alex-Sob wants to merge 4 commits intodotnet:mainfrom
Alex-Sob:dev/alex-sob/avoid-concurrentdictionary-allocation
Open

Avoid ConcurrentDictionary allocation in DisposeObjectsBeforeLosingScope#54127
Alex-Sob wants to merge 4 commits intodotnet:mainfrom
Alex-Sob:dev/alex-sob/avoid-concurrentdictionary-allocation

Conversation

@Alex-Sob
Copy link
Copy Markdown

Description

Currently DisposeObjectsBeforeLosingScope analyzer always allocates a ConcurrentDictionary<K, V> when it's initialized. As it's used to avoid reporting duplicate diagnostics for the same location, it's only needed when there are rule violations in code.

Suggested improvement

Defer dictionary allocation until it's actually needed in the case when rule violations are detected. This should avoid the allocation for successful builds.

Testing

All unit tests for this analyzer passed.

This PR has already been reviewed by @stephentoub (the original was created in the wrong repo)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant