Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Add IsKnownConstant jit helper and optimize 'str == ""' with str.StartsWith('c') #63734
Add IsKnownConstant jit helper and optimize 'str == ""' with str.StartsWith('c') #63734
Changes from 13 commits
9f55fa6
7d3ef94
0a717aa
407a953
9d45461
2f8a034
4883a46
aa88cf9
64843f0
2ebdae9
e264d27
f08a182
8e5fd0d
e2ebf30
895abc4
45bfe7c
80f9ddd
eebd8d1
e0e3e51
5b2fbfe
30e1855
3cb8402
7c7c264
a9b85fc
a3e5f3c
4947947
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
Why do we need to check
OptimizationEnabled
here? We have have early out for disabled optimizations before this switch.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.
Thanks, removed
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.
The unnecessary
OptimizationEnabled
check is in a few other intrinsics as well. You can delete it there too while you are on it.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.
String literals get fetched via extra indirections. How does this work? Where do the extra indirections get the
GTK_CONST
flag?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.
Ah ok, the PR description mentions that this does not work.
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.
string.Empty
andstatic readonly string
don't work (but can be arranged). Normal string literals do work because we import them as GT_CNS_STR and expand to indirections later in morphThere 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.
Sadly for diffs, we prefer
string.Empty
over""
in BCL, also all comparisons against empty strings were manually converted tostr?.Length == 0
over the codebase in https://github.com/dotnet/runtime/pull/36443/filesThere 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.
To be clear, they weren't converted to
str?.Length == 0
, or at least not 99% of them (I just re-skimmed the diff and didn't see any of those). These were all cases where we'd already checked the string for null, and so a simple length check was sufficient and clear, or where the string was being checked for null or empty, and thus it was clearer and more consistent with guidelines to use IsNullOrEmpty. I'd have pushed back on a change that tried to usestr?.Length == 0
everywhere :)(That said, it speaks to just how common
== ""
actually is in code.)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.
@stephentoub ah makes sense for me now why your analyzer found 100 cases in #63719
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.
Should
CA1820
be removed when all these changes defeat its perf improvement reasoning?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.
It's already disabled by default. If there ends up being zero benefit after these improvements (including subsequent ones to get string.Empty and the like), we could consider deleting it entirely from the SDK. I wouldn't rush to that, though.