Skip to content

Conversation

@jamescrosswell
Copy link
Collaborator

@jamescrosswell jamescrosswell commented Sep 20, 2023

#skip-changelog

This is an alternative approach to finding the last active span... rather than a for loop over all the Spans (which we store in a ConcurrentBag), this approach keeps all the spans on a Stack and inspects the most recent one(s) to return the last active span when required... all of which is guarded by a Mutex.

This approach actually uses slightly more memory in the trivial case of <= 10 spans... but vs the loop approach memory consumption for the 100 spans scenario drops by 63.25% from 724.02 KB to 266.09 KB.

Before

Method SpanCount Mean Error StdDev Gen0 Gen1 Allocated
'Create spans for scope access' 1 52.05 us 242.80 us 13.309 us 5.2490 1.6479 18.92 KB
'Create spans for scope access' 10 164.61 us 55.00 us 3.015 us 12.2070 4.1504 63.88 KB
'Create spans for scope access' 100 2,287.86 us 1,098.36 us 60.205 us 183.5938 50.7813 724.02 KB

After

Method SpanCount Mean Error StdDev Gen0 Gen1 Allocated
'Create spans for scope access' 1 28.45 us 13.270 us 0.727 us 4.6387 1.5869 16.64 KB
'Create spans for scope access' 10 84.98 us 6.361 us 0.349 us 9.3994 2.5635 39.17 KB
'Create spans for scope access' 100 657.54 us 54.581 us 2.992 us 57.6172 16.6016 266.09 KB

@jamescrosswell jamescrosswell merged commit 2f48c0a into last-active-span-memory Sep 20, 2023
@jamescrosswell jamescrosswell deleted the last-active-span-alternate branch September 20, 2023 09:05
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.

4 participants