Skip to content

Combining the -replace operator with a lookbehind assertion slowed down by a factor of 30+ between v6.0.2 and v6.1.0-preview.2 #6976

@mklement0

Description

@mklement0

Note: I have not tried to analyze whether the problem is in PowerShell or CoreFx; on the PowerShell side, new features were recently added to -replace - see #6029 - but I have no idea whether this symptom relates to that.

The problem appears to be specific to -replace; using -match does not exhibit the symptom.

Steps to reproduce

Run the following command line:

  • first on v6.0.2 (the current stable release as of this writing).

  • then on v6.1.0-preview.2 (the current preview release).

$arr =  (, 'fooo') * 1e6; (Measure-Command { $arr -replace '(?<=.{3}).+' }).TotalSeconds

Expected behavior

Similar timings.

Actual behavior

Here are sample timings, in seconds, from a Windows 10 VM:

# v6.0.2
1.8444752

# v6.1.0-preview.2
# !! more than 30 times slower
61.5428622

Environment data

PowerShell Core v6.0.2
PowerShell Core v6.1.0-preview.2

Metadata

Metadata

Assignees

Labels

Resolution-FixedThe issue is fixed.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions