Handle PSObject argument specially in method invocation logging#18060
Handle PSObject argument specially in method invocation logging#18060
Conversation
| case string: | ||
| case BigInteger: | ||
| case var _ when baseType.IsEnum || baseType.IsPrimitive: | ||
| return baseObj.ToString(); |
There was a problem hiding this comment.
Please review the cases that are covered here, and let me know if any other cases should be added.
There was a problem hiding this comment.
We could take something from our TryFastTrackPrimitiveTypes() method.
There was a problem hiding this comment.
Added Guid, Uri, Version, and SemanticVersion to the list.
@iSazonov I cannot find the TryFastTrackPrimitiveTypes method.
There was a problem hiding this comment.
@iSazonov I cannot find the
TryFastTrackPrimitiveTypesmethod.
Ye it's a nested method
PowerShell/src/System.Management.Automation/engine/MshObject.cs
Lines 1260 to 1294 in 397bd87
There was a problem hiding this comment.
Thanks! Added decimal to the list.
There was a problem hiding this comment.
Also re-arrange the order of the case clauses, based on the likelihood of those types being used as arguments.
There was a problem hiding this comment.
Use if statement instead of switch because the switch statement generates IL to check "is the instance of this type" for every case branch that matches a type, which is unnecessary. Also, it's easier to arrange the comparison order with if statements.
|
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
|
/backport to release/v7.3.0-rc.1 |
|
🎉 Handy links: |
PR Summary
Fix #18033
The
ToStringimplementation ofPSObjectdoes extra work on the base object, for example, unrolling the base object if it's enumerable, which is very expensive.For method invocation logging, we should avoid calling
ToStringon aPSObjectargument. Instead,PSObject, we represent it as"PSObject{}".PSObject, or is aPSObjectwrapping a base object, we represent it asbaseObj.ToString().Here are some log messages with this change:
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.