Closed
Labels
area-System.Diagnostics.Processsize-reductionIssues impacting final app size primary for size sensitive workloads
Description
@jkotas @adamsitnik I wonder if you have some insights why
Processends up being difficult to trim?
It always drags in a lot of performance counter related functionality and the dependencies are not straightforward to break without observable behavior changes. (It may be possible to improve this, it is just not straightforward.)
For example, here is a dependency chain from https://github.com/MichalStrehovsky/sizoscope for a simple app that just does Process.Start("notepad.exe").WaitForExit()
Originally posted by @jkotas in #126192 (comment)
Reacted by Copilot
Metadata
Metadata
Labels
area-System.Diagnostics.Processsize-reductionIssues impacting final app size primary for size sensitive workloads
Activity
dotnet-policy-service commentedon Mar 30, 2026
Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.
dotnet-policy-service commentedon Mar 30, 2026
Tagging subscribers to 'size-reduction': @eerhardt, @SamMonoRT
See info in area-owners.md if you want to be subscribed.
[-]Investigate improving trimabiity of System.Diagnostics.Process[/-][+]Investigate improving trimabliity of System.Diagnostics.Process[/+][-]Investigate improving trimabliity of System.Diagnostics.Process[/-][+]Investigate improving trimability of System.Diagnostics.Process[/+]tmds commentedon Mar 31, 2026
On Linux, these seem to be adding size:
ToStringbrings with it everything needed forProcessInfo(though it only needs theProcessName):runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/Process.cs
Lines 1487 to 1514 in 2f94e9d
Socketswhich then brings inSocketsTelemetry(ActivitySource, ...).tmds commentedon Mar 31, 2026
@jkotas @adamsitnik if you have some suggestions based on the above, I'd be interested to try them out.
adamsitnik commentedon Mar 31, 2026
I think once we have #47631 which should allow to poll any descriptor using epoll/kqueue we can improve #125512 and make
FileStreamuse it (currently the async read/write methods are going to perform a blocking poll). ThenFileStreamwould be great for any file on every OS and we could just useFileStreamfor every platform.jkotas commentedon Mar 31, 2026
This one may be improved by a straightforward refactoring, potentially creating a dedicated method to get ProcessName only. You may want to start by deleting implementation of ToString and measuring the savings in NAOT binary to see how much you can play with.
Improve trimability of System.Diagnostics.Process by lazily initializ…
MichalStrehovsky commentedon Apr 6, 2026
A quick way to try things like this is the workflow from: dotnet/winforms#9911 (comment)
For a method like ToString, replace
stubin the XML withremove(stub will stub out the method but only certain data types are supported;removewill make the method throw unconditionally).Improve trimability of System.Diagnostics.Process by lazily initializ…