Merge TypesV3_Ps1Xml.cs with Types_Ps1Xml.cs#10575
Merge TypesV3_Ps1Xml.cs with Types_Ps1Xml.cs#10575iSazonov wants to merge 6 commits intoPowerShell:masterfrom
Conversation
This reverts commit 1042dfb.
c18343b to
114dc29
Compare
|
I think merging |
JamesWTruher
left a comment
There was a problem hiding this comment.
from a code perspective, I don't think there's anything wrong with this, other than my suggestions below. However, I'm wondering why we need this code at all any longer. We don't need back-compat with V3 and we've eliminated the need to have references to the files at all. Could we remove references to *types.ps1xml entirely and just rely on the .cs files?
| @@ -1417,7 +1417,6 @@ private static InitialSessionState CreateRestrictedForRemoteServer() | |||
|
|
|||
| List<string> allowedTypes = new List<string>(); | |||
There was a problem hiding this comment.
| List<string> allowedTypes = new List<string>(); | |
| List<string> allowedTypes = new List<string>() { "types.ps1xml" }; |
|
|
||
| // System.Management.Automation formats & types files | ||
| Collection<string> types = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" }); | ||
| Collection<string> types = new Collection<string>(); |
There was a problem hiding this comment.
| Collection<string> types = new Collection<string>(); | |
| Collection<string> types = new Collection<string>() { "types.ps1xml" }; |
| "Help.format.ps1xml","HelpV3.format.ps1xml","PowerShellCore.format.ps1xml","PowerShellTrace.format.ps1xml", | ||
| "Registry.format.ps1xml"}); | ||
| Collection<string> smaTypes = new Collection<string>(new string[] { "types.ps1xml", "typesv3.ps1xml" }); | ||
| Collection<string> smaTypes = new Collection<string>(); |
There was a problem hiding this comment.
| Collection<string> smaTypes = new Collection<string>(); | |
| Collection<string> smaTypes = new Collection<string>() { "types.ps1xml" }; |
Now types.ps1xml is only a key to reference predefined types (also there is still GetEvent.types.ps1xml) which we load in each runspace at first step. It is not perf critical and I believe we could refactor the code. At least the code could become more readable. |
|
@daxian-dbw Could you please review and merge? |
| ProcessTypeData(filePath, errors, Types_Ps1Xml.Get()); | ||
| result = true; | ||
| } | ||
| else if (string.Equals(Path.Combine(psHome, "typesv3.ps1xml"), filePath, StringComparison.OrdinalIgnoreCase)) |
There was a problem hiding this comment.
This method is used by public TypeTable(IEnumerable<string> typeFiles). This is a public API and this change is potentially a breaking change if the typeFiles passed to that public constructor contains types3.ps1xml.
There was a problem hiding this comment.
I added new commit to partially address the breaking.
After that I hope the breaking change will be in gray area.
The only scenario that we cannot fix is to load 'typesv3.ps1xml' file without 'types.ps1xml'. This scenario is incredible.
| { | ||
| // Workaround for a scenario where we get the 'typesv3.ps1xml' file name from public API. | ||
| // Now all types from 'typesv3.ps1xml' is in 'types.ps1xml' so we load 'types.ps1xml'. | ||
| ProcessTypeData("types.ps1xml", errors, Types_Ps1Xml.Get()); |
There was a problem hiding this comment.
This means types.ps1xml will be processed twice, which could potentially cause issue that I don't know of (conflicts?).
There was a problem hiding this comment.
There GetOrAdd() is used. (But it will slow down)
I'd prefer a breaking change (gray area) and get rid typesv3.ps1xml (and then types.ps1xml as James asked). It looks like very rarely edge case.
GitHub search https://github.com/search?q=TypeTable+typesv3.ps1xml&type=Code
This is certainly not an exhaustive test, but it returned nothing excluding PowerShell code.
This open way to make the code faster (currently ~30% in runspace creation).
There was a problem hiding this comment.
This open way to make the code faster (currently ~30% in runspace creation).
I don't think merging those two source files and eliminating types3.ps1xml would help much on the perf here.
I will let the committee review the proposed change.
There was a problem hiding this comment.
I don't think merging those two source files and eliminating types3.ps1xml would help much on the perf here.
My thought is that it opens a way for future optimizations.
There was a problem hiding this comment.
Just took a look at the code in TypeTable.cs, and duplicate TypeData will result in error during processing:
PowerShell/src/System.Management.Automation/engine/TypeTable.cs
Lines 2698 to 2702 in 36bc894
The GetOrAdd() is only to get the member collection of the type. Error will happen when processing members of the type.
There was a problem hiding this comment.
I tried the compiled artifact and get the error. If PowerShell Committee conclusion will be to have a workaround I will discover another workaround but I hope we will agree to remove.
|
Given that |
PR Summary
Move all type definitions from TypesV3_Ps1Xml.cs to Types_Ps1Xml.cs
Simplify the code that processed them.
PR Context
I remember Jason's comment that make no sense to have separate TypesV3_Ps1Xml.cs file.
I discovered this while did a performance measure runspace creation. There is biggest delay on type importing (up to 30%!). I don't expect that the change visibly increase performance but it open a way for further investigations.
PR Checklist
.h,.cpp,.cs,.ps1and.psm1files have the correct copyright headerWIP:or[ WIP ]to the beginning of the title (theWIPbot will keep its status check atPendingwhile the prefix is present) and remove the prefix when the PR is ready.