Skip to content

refactor: use [GeneratedRegex] and SearchValues on log hot paths#848

Merged
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-generatedregex-searchvalues
Jun 11, 2026
Merged

refactor: use [GeneratedRegex] and SearchValues on log hot paths#848
laurentiu021 merged 1 commit into
mainfrom
refactor/r8-generatedregex-searchvalues

Conversation

@laurentiu021

Copy link
Copy Markdown
Owner

What

Audit Round 8 (.NET 10 modernization) — findings #21 and #22. Two idiom upgrades 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(..., RegexOptions.Compiled) — build-time compiled, no runtime IL emit, AOT-friendly. The dynamic interpolated branch (built from the real user-profile directory) stays a runtime Regex, since an interpolated pattern 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. 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), and FirstLine scans the same \r\n set with the same trim. Existing SanitizePath and Event Log tests cover both.

Verification

  • Build: main + unit + integration, 0 errors / 0 warnings (Release). The [GeneratedRegex] source generator ran cleanly.

Notes

  • refactor: — no version bump, no release, no CHANGELOG entry required.

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.
@laurentiu021 laurentiu021 merged commit a99b012 into main Jun 11, 2026
4 checks passed
@laurentiu021 laurentiu021 deleted the refactor/r8-generatedregex-searchvalues branch June 11, 2026 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant