Skip to content

perf: counting discarded telemetry for client reports no longer allocates - #5687

Merged
ric-oliv merged 1 commit into
mainfrom
perf/counter-dictionary-alloc-5686
Oct 8, 2026
Merged

ric-oliv merged 1 commit into
mainfrom
perf/counter-dictionary-alloc-5686

Conversation

@jamescrosswell

Copy link
Copy Markdown
Collaborator

ThreadsafeCounterDictionary.Add and Increment passed new CounterItem() to ConcurrentDictionary.GetOrAdd, so every recorded discard allocated a CounterItem (24 B), even when the counter already existed. #5607 put these calls on hot paths, such as every dropped log or metric. The factory overload only creates the item for a new key.

The new test measures allocations with GC.GetAllocatedBytesForCurrentThread, so it only runs on .NET (not .NET Framework or mobile). It fails on main with 48 B, 24 B for each of its two calls.

Closes #5686
Part of #5634

🤖 Generated with Claude Code

…ates

ThreadsafeCounterDictionary.Add and Increment passed a new CounterItem to
GetOrAdd, allocating 24 B on every call even when the counter already
existed. Use the factory overload so the item is only created for a new key.

Closes #5686

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.13%. Comparing base (8973c9b) to head (61e0abc).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5687      +/-   ##
==========================================
- Coverage   75.21%   75.13%   -0.08%     
==========================================
  Files         515      515              
  Lines       18989    18989              
  Branches     3693     3695       +2     
==========================================
- Hits        14282    14267      -15     
- Misses       3852     3867      +15     
  Partials      855      855              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell
jamescrosswell marked this pull request as ready for review October 7, 2026 20:47
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Oct 7, 2026

@ric-oliv ric-oliv 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.

Nice!

@ric-oliv
ric-oliv merged commit 803adc0 into main Oct 8, 2026
52 checks passed
@ric-oliv
ric-oliv deleted the perf/counter-dictionary-alloc-5686 branch October 8, 2026 09:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThreadsafeCounterDictionary allocates a CounterItem on every recorded drop

2 participants