-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Performance Issue with IsWindowsService
due to Repeated Process Lookups
#93613
Comments
Tagging subscribers to this area: @dotnet/area-extensions-hosting Issue DetailsDescriptionThe To reproduce this issue, simply call the ConfigurationThe issue was discovered on .NET 6.0, running on a Windows 11 Pro x64 (build 22621.1555) machine with the Regression?This issue has been present since the introduction of the DataEach call to AnalysisThe issue seems to stem from the method retrieving its parent process each time it is called. A potential solution could be to cache the parent process of the current process when the method is called for the first time, and then use this cached value in subsequent calls. This would prevent the need for repeated, time-consuming lookups.
|
We might want to cache the parent process |
@JKamsker any interest in offering a PR? |
Whoops, I somehow didn't get the notifications 😅 |
Description
The
WindowsServiceHelpers.IsWindowsService
method in theMicrosoft.Extensions.Hosting.WindowsServices
package has a performance issue. It retrieves its parent process each time it is called, which takes approximately 35.93ms. While this may not seem significant, the time accumulates when the method is used multiple times, leading to noticeable delays.To reproduce this issue, simply call the
WindowsServiceHelpers.IsWindowsService
method multiple times in a loop.Configuration
The issue was discovered on .NET 6.0, running on a Windows 11 Pro x64 (build 22621.1555) machine with the
Microsoft.Extensions.Hosting.WindowsServices
package version 6.0.2.However, it is likely to be present on any system where this package is used. The machine had about 600 processes running at the time of testing. The test was done in release mode.
Regression?
This issue has been present since the introduction of the
WindowsServiceHelpers.IsWindowsService
method. It is not a regression from a previous build or release.Data
Each call to
WindowsServiceHelpers.IsWindowsService
takes approximately 35.93ms due to the method retrieving its parent process each time. When used multiple times, these delays stack up. For example, calling the method 100 times would result in a delay of approximately 3.59 seconds.Analysis
The issue seems to stem from the method retrieving its parent process each time it is called. A potential solution could be to cache the parent process of the current process when the method is called for the first time, and then use this cached value in subsequent calls. This would prevent the need for repeated, time-consuming lookups.
The text was updated successfully, but these errors were encountered: