Skip to content

Performance regression in System.ServiceProcess.ServiceController, .Net Core App 2.1 #27189

@PaulHigin

Description

@PaulHigin

This was found in PowerShell Core6 (https://github.com/PowerShell/PowerShell) while investigating PowerShell cmdlet perf regression. I tracked the perf regression to this .Net type:

System.ServiceProcess.ServiceController

Using this type is approximately 30 times slower when running under .Net CoreApp 2.1

Repro steps:

using System;
using System.ServiceProcess;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Console.WriteLine("Starting loop");
            var start = DateTime.Now;

            for (var i=0; i<100; i++)
            {
                var winRMService = new ServiceController("WinRM");
                if (winRMService != null)
                {
                    var status = winRMService.Status;
                }
            }

            var end = DateTime.Now;

            System.Console.WriteLine("End loop");
            System.Console.WriteLine(String.Format("Time in milliseconds = {0}", (end - start).Milliseconds));
            System.Console.WriteLine("Press any key to continue");
            System.Console.ReadKey();
        }
    }
}

Results:
Under .Net Core App 2.1
Time in milliseconds = 714

Under .Net Full CLR
Time in milliseconds = 24

Expected:
Use of ServiceController type should have approximately the same performance between each version of .Net.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions