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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace a few Regex static method calls #728
Merged
Merged
Conversation
This file contains 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
github-actions
bot
added
.NET
Issue or Pull requests regarding .NET code
kernel
Issues or pull requests impacting the core kernel
kernel.core
labels
Apr 28, 2023
The static methods on Regex are convenient, but they're also a bit of a performance trap. Parsing regexes is fairly expensive, so that static methods employ a MRU cache to avoid reparsing on every use, but a) that cache has cost to access and b) the cache is very small by default. The net result is usage of other static Regex methods elsewhere in the app can make the use of the static methods in SK much more expensive. Regex is thread-safe, and it's better to just store the necessary instances into readonly static fields and then use the instance methods on those.
stephentoub
force-pushed
the
instanceregex
branch
from
April 28, 2023 15:54
a22ce3a
to
ace66fd
Compare
lemillermicrosoft
approved these changes
Apr 28, 2023
lemillermicrosoft
added
the
PR: ready to merge
PR has been approved by all reviewers, and is ready to merge.
label
Apr 28, 2023
dluc
pushed a commit
to dluc/semantic-kernel
that referenced
this pull request
Apr 30, 2023
### Motivation and Context Avoid use of Regex's static methods. ### Description The static methods on Regex are convenient, but they're also a bit of a performance trap. Parsing regexes is fairly expensive, so that static methods employ a MRU cache to avoid reparsing on every use, but a) that cache has cost to access and b) the cache is very small by default. The net result is usage of other static Regex methods elsewhere in the app can make the use of the static methods in SK much more expensive. Regex is thread-safe, and it's better to just store the necessary instances into readonly static fields and then use the instance methods on those. Note that there is an analyzer that flags these, but it's only available when targeting .NET 7+, where it recommends (and provides a fixer) for turning them into source-generated regexes using [GeneratedRegex(...)].
codebrain
pushed a commit
to searchpioneer/semantic-kernel
that referenced
this pull request
May 16, 2023
### Motivation and Context Avoid use of Regex's static methods. ### Description The static methods on Regex are convenient, but they're also a bit of a performance trap. Parsing regexes is fairly expensive, so that static methods employ a MRU cache to avoid reparsing on every use, but a) that cache has cost to access and b) the cache is very small by default. The net result is usage of other static Regex methods elsewhere in the app can make the use of the static methods in SK much more expensive. Regex is thread-safe, and it's better to just store the necessary instances into readonly static fields and then use the instance methods on those. Note that there is an analyzer that flags these, but it's only available when targeting .NET 7+, where it recommends (and provides a fixer) for turning them into source-generated regexes using [GeneratedRegex(...)].
dehoward
pushed a commit
to lemillermicrosoft/semantic-kernel
that referenced
this pull request
Jun 1, 2023
### Motivation and Context Avoid use of Regex's static methods. ### Description The static methods on Regex are convenient, but they're also a bit of a performance trap. Parsing regexes is fairly expensive, so that static methods employ a MRU cache to avoid reparsing on every use, but a) that cache has cost to access and b) the cache is very small by default. The net result is usage of other static Regex methods elsewhere in the app can make the use of the static methods in SK much more expensive. Regex is thread-safe, and it's better to just store the necessary instances into readonly static fields and then use the instance methods on those. Note that there is an analyzer that flags these, but it's only available when targeting .NET 7+, where it recommends (and provides a fixer) for turning them into source-generated regexes using [GeneratedRegex(...)].
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
kernel
Issues or pull requests impacting the core kernel
.NET
Issue or Pull requests regarding .NET code
PR: ready to merge
PR has been approved by all reviewers, and is ready to merge.
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.
Motivation and Context
Avoid use of Regex's static methods.
Description
The static methods on Regex are convenient, but they're also a bit of a performance trap. Parsing regexes is fairly expensive, so that static methods employ a MRU cache to avoid reparsing on every use, but a) that cache has cost to access and b) the cache is very small by default. The net result is usage of other static Regex methods elsewhere in the app can make the use of the static methods in SK much more expensive. Regex is thread-safe, and it's better to just store the necessary instances into readonly static fields and then use the instance methods on those.
Note that there is an analyzer that flags these, but it's only available when targeting .NET 7+, where it recommends (and provides a fixer) for turning them into source-generated regexes using [GeneratedRegex(...)].
Contribution Checklist
dotnet format