KEMBAR78
MethodInvocationLogging - Performance regression · Issue #24459 · PowerShell/PowerShell · GitHub
Skip to content

MethodInvocationLogging - Performance regression #24459

@trackd

Description

@trackd

Prerequisites

Steps to reproduce

The method invocation logging is tanking the performance of some scripts..

note: this does not seem to affect all.. Windows 10 machines appear unaffected.

I'm running Windows 11 24H2, fully updated.

saw #21473 but that seems scoped entirely to the memory issues.

also seen the various issues related to privacy and security.

This issue is limited to performance.

disclaimer: 7.5.0-P99 is a local build from main branch that just flips the #if UNIX from #24451. 
patching out the LogMemberInvocation in MiscOps.cs
it's also built with dotnet 9 rc.2

a simplified repro, run below in 5.1 and 7.3+

1..10 | ForEach-Object { 
    Measure-Command -Expression {
        $list = [System.Collections.Generic.List[int]]::new()
        foreach ($i in 1..22500) {
            $list.Add($i)
        }
    } 
} | Measure-Object -Property TotalMilliseconds -Average -Sum

We can clearly see a very big difference between Defender RTP on/off.

Proposal

  • Scope the MethodInvocation logging to dangerous methods.

    exclusion list based on namespaces, params, method names.. not sure the best approach here.

  • provide a way for admin-level opt out of MethodInvocationLogging.

from real code, i've seen a function go from 260ms to 2800ms.. over 10x increase.

the funniest part is that now it seems the fastest way to run Powershell on Windows is through WSL 🤷‍♂️

repro script

the script basically does 22.5k method invocations x 2, one with math and one with list.add()

Expected behavior

# TimeResolution = TotalMilliseconds, numberOfTestRuns = 100
# With Defender Real Time Protect Off

PSVersion Test        TimeAverage RelativeSpeed
--------- ----        ----------- -------------
7.2.23    List.Add()         1,44 1x
7.5.0-P99 List.Add()         1,48 1,03x
5.1       List.Add()         1,80 1,26x
7.4.5     List.Add()         8,48 5,9x
7.5.0-P5  List.Add()         8,50 5,92x
7.2.23    Square Root       21,45 1x
7.5.0-P99 Square Root       24,16 1,13x
5.1       Square Root       26,43 1,23x
7.4.5     Square Root       30,63 1,43x
7.5.0-P5  Square Root       30,83 1,44x

Actual behavior

# TimeResolution = TotalMilliseconds, numberOfTestRuns = 100
# With Defender Real Time Protect ON

PSVersion Test        TimeAverage RelativeSpeed
--------- ----        ----------- -------------
7.5.0-P99 List.Add()         1,51 1x
7.2.23    List.Add()         1,52 1,01x
5.1       List.Add()         1,78 1,18x
7.5.0-P5  List.Add()       307,42 204,27x
7.4.5     List.Add()       317,53 210,98x
7.2.23    Square Root       21,93 1x
7.5.0-P99 Square Root       25,76 1,17x
5.1       Square Root       26,03 1,19x
7.5.0-P5  Square Root       74,43 3,39x
7.4.5     Square Root       77,46 3,53x

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.5
PSEdition                      Core
GitCommitId                    7.4.5
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

image

top left, custom build
top right, Windows Powershell 5.1
bottom left, 7.4.5 running in WSL
bottom right, 7.5.0-Preview5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.WG-Engine-Performancecore PowerShell engine, interpreter, and runtime performanceWG-NeedsReviewNeeds a review by the labeled Working GroupWG-Securitysecurity related areas such as JEA

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions