-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Improve performance by having better primitives on PSObject #8785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1f40247
fa775bd
8f14671
fa3ff7a
7ecc094
f110a8c
92e3ea4
b28ce56
9b40624
f205055
f6f3560
f07a3ea
a4da06e
4881f11
1519087
1e2a570
2d5c0e2
749a362
cc2d003
702f14d
af563aa
67981d5
ed74852
c708c3d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -464,65 +464,19 @@ private static ViewGenerator SelectViewGeneratorFromProperties(FormatShape shape | |
| /// </summary> | ||
| internal static class OutOfBandFormatViewManager | ||
| { | ||
| internal static bool IsPropertyLessObject(PSObject so) | ||
| private static bool IsNotRemotingProperty(string name) | ||
| { | ||
| List<MshResolvedExpressionParameterAssociation> allProperties = AssociationManager.ExpandAll(so); | ||
|
|
||
| if (allProperties.Count == 0) | ||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (allProperties.Count == 3) | ||
| { | ||
| foreach (MshResolvedExpressionParameterAssociation property in allProperties) | ||
| { | ||
| if (!property.ResolvedExpression.ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| if (allProperties.Count == 4) | ||
| { | ||
| foreach (MshResolvedExpressionParameterAssociation property in allProperties) | ||
| { | ||
| if (!property.ResolvedExpression.ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) | ||
| && !property.ResolvedExpression.ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| if (allProperties.Count == 5) | ||
| { | ||
| foreach (MshResolvedExpressionParameterAssociation property in allProperties) | ||
| { | ||
| if (!property.ResolvedExpression.ToString().Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase) && | ||
| !property.ResolvedExpression.ToString().Equals(RemotingConstants.SourceLength, StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| var isRemotingPropertyName = name.Equals(RemotingConstants.ComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) | ||
| || name.Equals(RemotingConstants.ShowComputerNameNoteProperty, StringComparison.OrdinalIgnoreCase) | ||
| || name.Equals(RemotingConstants.RunspaceIdNoteProperty, StringComparison.OrdinalIgnoreCase) | ||
| || name.Equals(RemotingConstants.SourceJobInstanceId, StringComparison.OrdinalIgnoreCase) | ||
| || name.Equals(RemotingConstants.SourceLength, StringComparison.OrdinalIgnoreCase); | ||
| return !isRemotingPropertyName; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
| private static readonly MemberNamePredicate NameIsNotRemotingProperty = IsNotRemotingProperty; | ||
|
|
||
| return false; | ||
| } | ||
| private static bool HasNonRemotingProperties(PSObject so) => so.GetFirstPropertyOrDefault(NameIsNotRemotingProperty) != null; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, I guess all the
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that is where most of the speedup comes from. We where getting all properties to see if we had any, and we did so for all objects. Hence my comment above about the possibility to cache this per type.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That was what started the whole chain of changes. Getting a fast, low-allocation, way of satisfying the demands the formatting system has on the object model. It took up a huge chunk of the total time budget. After these changes, the time is spent doing actual formatting of the objects. There are probably things to look at there to, but that is for another day :) |
||
|
|
||
| internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext errorContext, PSPropertyExpressionFactory expressionFactory, | ||
| TypeInfoDataBase db, PSObject so, int enumerationLimit, bool useToStringFallback, out List<ErrorRecord> errors) | ||
|
|
@@ -549,8 +503,8 @@ internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext er | |
| } | ||
| else | ||
| { | ||
| if (DefaultScalarTypes.IsTypeInList(typeNames) || | ||
| IsPropertyLessObject(so)) | ||
| if (DefaultScalarTypes.IsTypeInList(typeNames) | ||
| || !HasNonRemotingProperties(so)) | ||
| { | ||
| // we force a ToString() on well known types | ||
| return GenerateOutOfBandObjectAsToString(so); | ||
|
|
@@ -575,7 +529,7 @@ internal static FormatEntryData GenerateOutOfBandData(TerminatingErrorContext er | |
|
|
||
| FormatEntryData fed = outOfBandViewGenerator.GeneratePayload(so, enumerationLimit); | ||
| fed.outOfBand = true; | ||
| fed.SetStreamTypeFromPSObject(so); | ||
| fed.writeStream = so.WriteStream; | ||
|
|
||
| errors = outOfBandViewGenerator.ErrorManager.DrainFailedResultList(); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.