-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache process info where possible and dispose Process objects. #11274
Conversation
Related to #11160 |
25b098e
to
8a74a3e
Compare
I tried rebasing and/or merging with main, which made a mess. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've left some comments. Overall I like it.
Ping me when ready please and I'll approve.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Overall looks ready to go!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was experimenting with adding these to our banned-API list and found a few uses which would benefit from a long-lived Process.GetCurrentProcess()
to call other methods/properties on it. Would that cause a problem or should we consider it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
I talked with @AR-May and this has an impact that is below what we can detect with PerfStar. At least it is definitely not a regression and since it is a neat code cleanup, I'm voting for merge. |
Fixes #
Context
There are multiple places where information about the current process is retrieved. There is a non-trivial cost to getting this information and the Process objects should be disposed to avoid additional GC cost due to the finalizer running. This change adds properties in EnvironmentUtilities that cache info such as the current process ID (this implementation is copied from .NET 6), and in some instances, updates some callers to dispose of the Process object for uncommon usages.
Changes Made
Testing
Notes