Cache process info where possible and dispose Process objects.#11274
Cache process info where possible and dispose Process objects.#11274JanProvaznik merged 3 commits intodotnet:mainfrom
Conversation
|
Related to #11160 |
25b098e to
8a74a3e
Compare
|
I tried rebasing and/or merging with main, which made a mess. |
SimaTian
left a comment
There was a problem hiding this comment.
I've left some comments. Overall I like it.
Ping me when ready please and I'll approve.
JanKrivanek
left a comment
There was a problem hiding this comment.
Thank you!
Overall looks ready to go!
rainersigwald
left a comment
There was a problem hiding this comment.
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?
|
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