-
Notifications
You must be signed in to change notification settings - Fork 847
Optimize empty string pattern matching with null-safe length checks #19189
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
T-Gro
reviewed
Jan 5, 2026
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Optimize F# pattern match for empty string equality
Optimize empty string pattern matching with null-safe length checks
Jan 5, 2026
vzarytovskii
reviewed
Jan 6, 2026
…ion in BuildSwitch only Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…ompatibility Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…, move release notes to 10.0.200 Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…ontexts Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
Member
|
/run ilverify |
Contributor
🔧 CLI Command Report
✅ Patch applied: |
T-Gro
approved these changes
Jan 14, 2026
abonie
reviewed
Jan 19, 2026
abonie
approved these changes
Jan 19, 2026
Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
auto-merge was automatically disabled
January 20, 2026 09:02
Head branch was pushed to by a user without write access
T-Gro
approved these changes
Jan 22, 2026
Member
|
/run ilverify |
Contributor
🔧 CLI Command Report
✅ Patch applied: |
This was referenced Jan 23, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
NO_RELEASE_NOTES
Label for pull requests which signals, that user opted-out of providing release notes
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.
String Empty Pattern Match Optimization
This PR optimizes empty string pattern matching to use null-safe
.Length == 0checks instead of string equality comparisons for better performance.Implementation
The optimization is implemented purely as a code generation optimization in
BuildSwitch(PatternMatchCompilation.fs), whereConst (String "")patterns are detected and compiled to emit:brfalse) - skipped if we're in a null-filtered contextcallvirt get_Length()followed by comparison with zero)Key Features
Const (String "")discriminator - no special handlingString.EqualsisNullFilteredparameter tracks when we're in a null-filtered context (after an IsNull test), allowing redundant null checks to be skipped| "" -> ...(optimized with null check + length check)| null -> ... | "" -> ...(both cases handled separately)| null | "" -> ...(bundled clauses - single null check from IsNull, then length check without additional null test)Changes Made
isNullFilteredboolean parameter to track null-safe contextsnullFiltered=trueafter IsNull test and passes to recursive calls.Length == 0check, conditionally skipping null test whenisNullFiltered=truemkGetStringLengthto support the optimizationTesting
--optimize+flag| null | "" -> ...and| "" | null -> ...)Generated IL Example
Before (string equality):
After (null-safe length check):
The changes are minimal and surgical, affecting only the code generation path for empty string constants without any changes to pattern analysis, type definitions, or data structures.
Original prompt
This pull request was created from Copilot chat.
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.