Skip to content

Avoid ConcurrentDictionary.Count on the Windows proxy lookup path - #136519

Merged
MihaZupan merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/avoid-proxy-cache-count
Oct 27, 2026
Merged

MihaZupan merged 1 commit into
dotnet:mainfrom
EgorBo:egorbo/avoid-proxy-cache-count

Conversation

@EgorBo

@EgorBo EgorBo commented Oct 27, 2026

Copy link
Copy Markdown
Member

Avoid calling ConcurrentDictionary.Count on every Windows system-proxy lookup, including when no proxies have failed.

Count is expensive: it acquires all of the dictionary's locks and sums the per-lock counts to provide a snapshot. This adds dictionary-wide locking to an otherwise lock-free lookup.

Check the cleanup deadline first and only inspect the cache size when cleanup is due. Empty and small caches still advance the deadline, keeping size checks throttled after the first interval.

Local before/after benchmarking showed faster proxy-cache lookups.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 77df0a3f-9ca3-4c0e-99be-ffc9e57c41ca
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 4 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @karelz, @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@EgorBo

EgorBo commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@MihaZupan can you take a look? I was just inspecting ConcurrentDictionary.Count usages in Libraries to find cases where it might be assumed that .Count is fast (it is very slow for CD).

@EgorBo
EgorBo requested a review from MihaZupan October 27, 2026 15:46

@MihaZupan MihaZupan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@MihaZupan
MihaZupan merged commit 2da7780 into dotnet:main Oct 27, 2026
86 of 90 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants