Skip to content

Conversation

@stephentoub
Copy link
Member

GetProcessesByName is loading all of the information for every process found, even if it'll immediately be thrown away because the name doesn't match.

[Benchmark]
public void GetProcessesByName()
{
    foreach (Process p in Process.GetProcessesByName("dotnet.exe"))
        p.Dispose();
}
Method Toolchain Mean Ratio Allocated Alloc Ratio
GetProcessesByName \main\corerun.exe 4.415 ms 1.00 622.43 KB 1.000
GetProcessesByName \pr\corerun.exe 4.066 ms 0.91 2.14 KB 0.003

@ghost
Copy link

ghost commented Apr 29, 2022

Tagging subscribers to this area: @dotnet/area-system-diagnostics-process
See info in area-owners.md if you want to be subscribed.

Issue Details

GetProcessesByName is loading all of the information for every process found, even if it'll immediately be thrown away because the name doesn't match.

[Benchmark]
public void GetProcessesByName()
{
    foreach (Process p in Process.GetProcessesByName("dotnet.exe"))
        p.Dispose();
}
Method Toolchain Mean Ratio Allocated Alloc Ratio
GetProcessesByName \main\corerun.exe 4.415 ms 1.00 622.43 KB 1.000
GetProcessesByName \pr\corerun.exe 4.066 ms 0.91 2.14 KB 0.003
Author: stephentoub
Assignees: stephentoub
Labels:

area-System.Diagnostics.Process

Milestone: -

@stephentoub stephentoub added this to the 7.0.0 milestone Apr 29, 2022
@stephentoub stephentoub added the tenet-performance Performance related issue label Apr 29, 2022
GetProcessesByName is loading all of the information for every process found, even if it'll immediately be thrown away because the name doesn't match.
@danmoseley danmoseley merged commit bfceef9 into dotnet:main May 1, 2022
@stephentoub stephentoub deleted the getprocessesalloc branch May 1, 2022 18:15
@stephentoub
Copy link
Member Author

Note this also fixed the unreported issue on Linux/macOS that passing null or empty string to GetProcessesByName shouldn't filter anything out but was filtering everything out.

@DrewScoggins
Copy link
Member

Improvement: dotnet/perf-autofiling-issues#5077

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants