Skip to content

Reduce allocations when Activity is enabled#11020

Merged
davidfowl merged 3 commits intomasterfrom
davidfowl/reduce-activity-allocs
Jun 10, 2019
Merged

Reduce allocations when Activity is enabled#11020
davidfowl merged 3 commits intomasterfrom
davidfowl/reduce-activity-allocs

Conversation

@davidfowl
Copy link
Copy Markdown
Member

@davidfowl davidfowl commented Jun 9, 2019

  • Remove string allocations caused by DiagnosticSource.Stop/StartActivity
  • Pass the HttpContext directly as the object for StartActivity and StopActivity to avoid the anonymous object allocation.
  • Though it's a bit ugly, added an HttpContext property to DefaultHttpContext to avoid breaking back-compat (which had to do reflection to get the HttpContext property anyways)

Contributes to #9594

Before:
image

After:
image

- Remove string allocations caused by DiagnosticSource.Stop/StartActivity
- Pass the HttpContext directly as the object for StartActivity and StopActivity to avoid the anonymous object allocation.
- Though it's a bit ugly, added an HttpContext property to DefaultHttpContext to avoid breaking back-compat (which had to do reflection to get the HttpContext property anyways)
Comment thread src/Http/Http/src/DefaultHttpContext.cs
- Mark HttpContext field as editable browsable never
- Ran code check
Comment thread src/Hosting/Hosting/src/Internal/HostingApplicationDiagnostics.cs Outdated
Co-Authored-By: Christopher Watford <christopher.watford@ge.com>
@davidfowl davidfowl merged commit d4a982f into master Jun 10, 2019
@ghost ghost deleted the davidfowl/reduce-activity-allocs branch June 10, 2019 20:37
@davidfowl
Copy link
Copy Markdown
Member Author

cc @lmolkova @SergeyKanzhelev as an FYI, this should be non breaking though.

{
hasDiagnosticListener = true;
_diagnosticListener.StartActivity(activity, new { HttpContext = httpContext });
StartActivity(activity, httpContext);
Copy link
Copy Markdown

@lmolkova lmolkova Jun 14, 2019

Choose a reason for hiding this comment

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

I like this and we may be able to update listener in time for 3.0 to support it. But it is breaking (i.e. there is no HttpContext property on HttpContext type), everyone who attempts to get it will fail.

Copy link
Copy Markdown

@lmolkova lmolkova Jun 14, 2019

Choose a reason for hiding this comment

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

ooops, you've added property on HttpConetxt 😂

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

HttpContext.HttpContext 😄

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

Labels

area-hosting Includes Hosting

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants