refactor: use [GeneratedRegex] and SearchValues on log hot paths#848
Merged
Conversation
Two .NET 10 idiom modernizations on hot/testable paths, behavior unchanged: - LogService is now a static partial class; the constant fallback user-path pattern is source-generated via [GeneratedRegex] (FallbackUserPathRegex) instead of new Regex(..., Compiled) — build-time compiled, no runtime IL emit, AOT-friendly. The dynamic interpolated branch (built from the real user-profile dir) stays a runtime Regex since it can't be source-generated. - EventLogService.FirstLine hoists a static SearchValues<char> for the \r\n scan and uses span IndexOfAny, removing the per-call char[] allocation on a path that runs once per projected event record (thousands per query). Both regex patterns and the FirstLine result are byte-identical to before.
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.
What
Audit Round 8 (.NET 10 modernization) — findings #21 and #22. Two idiom upgrades on hot/testable paths, behavior unchanged:
LogServiceis now astatic partial class. The constant fallback user-path pattern is source-generated via[GeneratedRegex](FallbackUserPathRegex) instead ofnew Regex(..., RegexOptions.Compiled)— build-time compiled, no runtime IL emit, AOT-friendly. The dynamic interpolated branch (built from the real user-profile directory) stays a runtimeRegex, since an interpolated pattern can't be source-generated.EventLogService.FirstLinehoists a staticSearchValues<char>for the\r\nscan and uses spanIndexOfAny, removing the per-callchar[]allocation. This runs once per projected event record (potentially thousands per query).Behavior guarantee (Protocol Q)
Identical. The fallback regex pattern is byte-for-byte
(?i)([A-Z]:\Users\)[^\]+(only the compilation strategy changes — same matches), andFirstLinescans the same\r\nset with the same trim. ExistingSanitizePathand Event Log tests cover both.Verification
[GeneratedRegex]source generator ran cleanly.Notes
refactor:— no version bump, no release, no CHANGELOG entry required.