Cache GUID validation regex - #142
Merged
Merged
Conversation
Avoid compiling the GUID validation regex on every call and use the source-generated regex on modern target frameworks.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The change is scoped, validated successfully, and has no unresolved review issues.
Pull request overview
Caches GUID validation regexes across supported target frameworks while preserving existing behavior.
Changes:
- Uses
[GeneratedRegex]on .NET 8+. - Uses a compiled static regex on older frameworks.
- Replaces
Match(...).SuccesswithIsMatch.
File summaries
| File | Description |
|---|---|
SharedCode.Core/Text/StringExtensions.cs |
Implements cached GUID regex validation. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
SummarySummary
CoverageSharedCode.Core - 29.5%
SharedCode.Core.Tests - 98.1%
SharedCode.Data - 8.3%
SharedCode.Data.Tests - 100%
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
IsGuidcall.[GeneratedRegex]on .NET 8+ and a compiled static regex on older target frameworks.Match(...).SuccesswithIsMatch(...).Performance scan: 10 opportunities
SharedCode.Core/Text/StringExtensions.cs:422; per-call regex construction and match-object work. Implemented here.StringExtensions.StripHtml; the pre-.NET 8 branch constructs a regex per call; cache a compiled fallback.DomainRegex,EmailAddressRegex,SlugRegEx,SlugRegEx2,UrlRegEx, andValidIpRegExare static patterns that could use[GeneratedRegex]on modern targets.Replacecalls, creating multiple intermediate strings; use a single-pass translation.Trim, and a final replacement; reduce intermediate strings with a single generated regex or span-based pass.SharedCode.Core/Enum.cs:95usesHashtable.ContainsKeyfollowed by an indexer, performing two lookups; use a typed dictionary and one lookup.SharedCode.Core/Extensions.cs:335uses the reflection-basedJsonSerializer.Serialize(input)overload; add cached options/source-generated contexts for known payloads.SharedCode.DependencyInjection/TypeSourceSelector.cs:231repeatedly enumerates defined types with LINQ; cache immutable scan results when the same assemblies are selected repeatedly.SharedCode.Core/IO/StreamExtensions.cscallsImageCodecInfo.GetImageEncoders()per image; cache the JPEG encoder.StreamExtensions.ToByteArray/ToByteArrayAsyncallocate and grow aMemoryStreambefore copying; pre-size when the input length is known and avoid redundant copies where possible.Validation
dotnet test SharedCode.Core.Tests\\Core.Tests.csproj --verbosity minimal— 782 passed, 2 skipped.dotnet build SharedCode.Core\\Core.csproj --no-restore --no-dependencies -p:GeneratePackageOnBuild=false --verbosity minimal— all five target frameworks built successfully.NU5019missingC:\logo.pngpath.