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
Treat [NullString]::Value
as the string type when resolving methods
#18080
Conversation
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) |
test/powershell/Language/Scripting/Scripting.Followup.Tests.ps1
Outdated
Show resolved
Hide resolved
test/powershell/Language/Scripting/Scripting.Followup.Tests.ps1
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with one notice.
internal static Type GetObjectType(object obj, bool debase) | ||
{ | ||
if (debase) | ||
{ | ||
return typeof(LanguagePrimitives.Null); | ||
obj = PSObject.Base(obj); | ||
} | ||
|
||
return obj == NullString.Value ? typeof(string) : obj?.GetType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it really hot path code? If so we could think about more tier-compilation-friendly methods:
internal static Type GetObjectTypeAfterDebase(object obj)
{
obj = PSObject.Base(obj);
return obj == NullString.Value ? typeof(string) : obj?.GetType();
}
internal static Type GetObjectTypeWithoutDebase(object obj) =>
obj == NullString.Value ? typeof(string) : obj?.GetType();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I know C# pretty well but never considered it from performance side. In C++, this function would be almost guaranteed to be inlined and the if
discarded or made unconditional. Is C#'s optimizer really not capable of it? Do you have some optimization guidelines I could read, e.g. when to use [AggressivelyInline]
I saw in some WriteToConsole
overloads?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a micro-optimization that we should avoid, as I don't think the difference is measurable.
PR Summary
Fix #18072
Treat
[NullString]::Value
as the string type when resolving methods.PR Checklist
.h
,.cpp
,.cs
,.ps1
and.psm1
files have the correct copyright headerWIP:
or[ WIP ]
to the beginning of the title (theWIP
bot will keep its status check atPending
while the prefix is present) and remove the prefix when the PR is ready.