Skip to content

Conversation

@powercode
Copy link
Collaborator

@powercode powercode commented Feb 26, 2019

PR Summary

Adds support for deriving from PSObject to create optimized CodeProperties, and uses this to implement the attached properties for FileSystem/Registry-Provider and the output of Get-Content.

This makes the FileSystemProvider roughly twice as fast getting items, and about 5 times faster getting content.

Memory usage of getting all item under c:\windows is 415Mb before the change, and 103Mb after.

To try it out:

Enable-ExperimentalFeature PSOptimizedProvider 

PR Context

PSNoteProperties are quite expensive. To provide core scenarios with a more performant alternative, this PR adds types derived from PSObject that are tailored for common scenarios in the providers.

The providers add six PSNoteProperties to each item, adding massively to the memory usage, and substantially to the time it takes to create the PSObjects wrapping the items.

The same thing happens with Get-Content where the attached properties can inflate the PSObjects many times over.

The gist of the change is the addition of an interface, IPSObjectExtendedMemberInfo and an attribute,
PSExtensionMemberAttribute, that the derived PSObjects can use to communicate with the ETS about what members to expose.

CoreAdapter has a new member, AddExtensionProperties that adds members with the attribute, and the interface provides a member

T GetMember<T>(MemberNamePredicate predicate)

that can be used to quickly determine if an object provides a property matching the predicate.

PR Checklist

@powercode powercode force-pushed the Perf/FileInfoPsProps branch 2 times, most recently from 17ed0b3 to 1fc03a1 Compare February 26, 2019 23:56
@daxian-dbw daxian-dbw self-assigned this Feb 27, 2019
@powercode
Copy link
Collaborator Author

Not sure why that test fails. It passes locally 🤔

@powercode powercode force-pushed the Perf/FileInfoPsProps branch 2 times, most recently from b6dd06d to 073cbc5 Compare March 1, 2019 01:19
@iSazonov
Copy link
Collaborator

iSazonov commented Mar 1, 2019

Verify Clear-Item with -WhatIf

It still fail. I don't see why - need to debug.

@powercode
Copy link
Collaborator Author

@iSazonov That seems like a genuine bug from my side. And windows only is easy to debug for me.

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 1, 2019

Perhaps I don't understand you comment but the test failed on Windows
https://powershell.visualstudio.com/PowerShell/_build/results?buildId=14744&view=logs&jobId=35656138-dd59-55dc-1472-6feeb4c97f57&taskId=41fef26b-4f6c-56d4-3d5d-1873b1a12853&lineStart=853&lineEnd=854&colStart=1&colEnd=1

Update: previous test seems works so only WhatIf parameter doesn't work.

@powercode
Copy link
Collaborator Author

powercode commented Mar 3, 2019

@iSazonov, @daxian-dbw Do you know how to test global experimental features?

In this case, I would like to run all test with the feature both enabled and disabled, to make sure I didn't break anything in the old behavior, and that is works with the optimizations.

I know about the flags to Start-PSPester, and I can run them locally, but I don't know how to enable running both for a large set of tests.

To you have any ideas on how to handle this?
Since I'm changing the binder, PSObject and ProviderBase, it would be good to have quite a lot of testing on it :)

@iSazonov
Copy link
Collaborator

iSazonov commented Mar 3, 2019

There is TestMetadata.json file.
See #7419

@daxian-dbw
Copy link
Member

daxian-dbw commented Mar 3, 2019

@powercode Here is the TestMetadata.json file: https://github.com/PowerShell/PowerShell/blob/master/test/tools/TestMetadata.json
Please look at it along with the Pester test example: https://github.com/PowerShell/PowerShell/blob/master/test/powershell/engine/ExperimentalFeature/ExperimentalFeature.Basic.Tests.ps1

TestMetadata.json allows you to define the experimental features and the corresponding tests to run. If an empty array is used for an experimental feature, that means all tests will run for the experimental feature.
When starting to Pester tests, we first run all tests without any experimental feature enabled, so the stable code gets exercised by all tests.
Then for each experimental feature defined in TestMetadata.json, Start-PSPester sets up the config file to enable the feature, and run the indicated tests with that feature enabled.

Sorry that I didn't update the testing doc with this. Will do that soon.

@stale
Copy link

stale bot commented Apr 26, 2019

This PR has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed if no further activity occurs within 10 days.
Thank you for your contributions.
Community members are welcome to grab these works.

@stale stale bot added the Stale label Apr 26, 2019
@daxian-dbw daxian-dbw removed the Stale label Apr 26, 2019
@powercode
Copy link
Collaborator Author

Keeping this alive. Will get back to it after PSConfEU

@SteveL-MSFT SteveL-MSFT added the Experimental Experimental Feature label Jun 4, 2019
@powercode powercode force-pushed the Perf/FileInfoPsProps branch 2 times, most recently from 64cf96d to 5943ad2 Compare June 7, 2019 22:19
@PoshChan
Copy link
Collaborator

PoshChan commented Jun 7, 2019

@powercode, your last commit had 2 failures in PowerShell-CI-windows
Get-ItemProperty.Should be able to access a property using the Path and name switches

Expected $null, but got C.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Management\Get-ItemProperty.Tests.ps1: line 36
36: 	$output.PSDrive | Should -Be $testprovider

String cmdlets.Select-String.Network path

Expected 2, but got 0.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Utility\string.tests.ps1: line 56
56:             (select-string -LiteralPath $fileNameAsNetworkPath "b").count | Should -Be 2

@PoshChan
Copy link
Collaborator

PoshChan commented Jun 7, 2019

@powercode, your last commit had 4 failures in PowerShell-CI-macos
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/vsts/agent/2.152.1/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/vsts/agent/2.152.1/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/vsts/agent/2.152.1/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Get-ItemProperty.Should be able to access a property using the Path and name switches

Expected $null, but got /.
at <ScriptBlock>, /Users/vsts/agent/2.152.1/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1: line 36
36: 	$output.PSDrive | Should -Be $testprovider

@PoshChan
Copy link
Collaborator

PoshChan commented Jun 7, 2019

@powercode, your last commit had 4 failures in PowerShell-CI-linux
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Get-ItemProperty.Should be able to access a property using the Path and name switches

Expected $null, but got /.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1: line 36
36: 	$output.PSDrive | Should -Be $testprovider

@powercode powercode force-pushed the Perf/FileInfoPsProps branch from 5943ad2 to b0b85a0 Compare November 9, 2019 23:14
internal sealed class FileSystem_Format_Ps1Xml
{
internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powercode, your last commit had 4 failures in PowerShell-CI-macos
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Get-ItemProperty.Should be able to access a property using the Path and name switches

Expected $null, but got /.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ItemProperty.Tests.ps1: line 36
36: 	$output.PSDrive | Should -Be $testprovider

internal sealed class FileSystem_Format_Ps1Xml
{
internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powercode, your last commit had 3 failures in PowerShell-CI-linux
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

internal sealed class FileSystem_Format_Ps1Xml
{
internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powercode, your last commit had 2 failures in PowerShell-CI-windows
Get-ItemProperty.Should be able to access a property using the Path and name switches

Expected $null, but got C.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Management\Get-ItemProperty.Tests.ps1: line 36
36: 	$output.PSDrive | Should -Be $testprovider

String cmdlets.Select-String.Network path

Expected 2, but got 0.
at <ScriptBlock>, D:\a\1\s\test\powershell\Modules\Microsoft.PowerShell.Utility\string.tests.ps1: line 56
56:             (select-string -LiteralPath $fileNameAsNetworkPath "b").count | Should -Be 2

internal sealed class FileSystem_Format_Ps1Xml
{
internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powercode, your last commit had 3 failures in PowerShell-CI-macos
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /Users/runner/runners/2.160.0/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

internal sealed class FileSystem_Format_Ps1Xml
{
internal static IEnumerable<ExtendedTypeDefinition> GetFormatData()
{
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@powercode, your last commit had 3 failures in PowerShell-CI-linux
Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: \foo:bar.txt

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: /foo:

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

Basic FileSystem Provider Tests.Validate basic FileSystem Cmdlets.Get-Content on Unix succeeds with folder and file with colon: :bar

Expected exactly 'Hello', but got $null.
at <ScriptBlock>, /home/vsts/work/1/s/test/powershell/Modules/Microsoft.PowerShell.Management/FileSystem.Tests.ps1: line 246
246:                 $files[0] | Get-Content | Should -BeExactly "Hello"

@ghost ghost added the Review - Needed The PR is being reviewed label May 27, 2020
@ghost
Copy link

ghost commented May 27, 2020

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@TravisEz13 TravisEz13 added Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept and removed Review - Needed The PR is being reviewed Review - Waiting on Author labels May 27, 2020
@ghost ghost added the Stale label Jun 11, 2020
@ghost
Copy link

ghost commented Jun 11, 2020

This pull request has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 15 days. It will be closed if no further activity occurs within 10 days of this comment.

This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Experimental Experimental Feature Stale Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants