-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Can the GetProcessesByName method reduce the number of arrays and Process objects created? #40768
Comments
Tagging subscribers to this area: @eiriktsarpalis |
@lindexi is this just a general observation, or is this causing performance impact in your own application? |
@danmosemsft this is just a general observation. |
@lindexi thanks, but unless something is self-evidently inefficient, we would need perf numbers to motivate increasing the complexity in this way. I will close this: feel free to reopen if you have such numbers. We recommend use of Benchmark.NET. I do agree with @jkotas that I do not think you will see a benefit. |
Apologies - I mixed this up with the other perf issue you opened (for registry). I have not evaluated this one. |
@lindexi would you like to send a PR? |
If we want to reduce memory allocation, we may want to filter the process name all the way through the NtProcessInfoHelper.GetProcessInfos, for Windows, where we have SYSTEM_PROCESS_INFORMATION.ImageName: runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Win32.cs Line 346 in f4d3913
and similarly for Linux: runtime/src/libraries/System.Diagnostics.Process/src/System/Diagnostics/ProcessManager.Linux.cs Line 187 in 6072e4d
|
Due to lack of recent activity, this issue has been marked as a candidate for backlog cleanup. It will be closed if no further activity occurs within 14 more days. Any new comment (by anyone, not necessarily the author) will undo this process. This process is part of our issue cleanup automation. |
This issue will now be closed since it had been marked |
Description
As written in the code, GetProcessesByName first calls GetProcesses to obtain all processes of the machine, and then filters the process name
But in fact, we can filter the process name in GetProcesses in advance.
If we do this, we can reduce the allocation length of the Process array and create some Process objects in the GetProcesses method
The text was updated successfully, but these errors were encountered: