[repo-assist] perf: cache compiled Regex per pattern in JsonSchema.validate - #1806
github-actions[bot] wants to merge 1 commit into
Conversation
JsonSchema.validate previously constructed a brand-new System.Text.RegularExpressions.Regex on every call for a schema with a string 'pattern' constraint. This meant every string value validated against the same schema (e.g. array items, or repeated object properties) recompiled the identical regex from scratch. This change caches compiled Regex instances in a ConcurrentDictionary keyed by pattern string, so the same pattern is only compiled once per process. No behavior change - same match results. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
/repo-assist fix the CI failure due to code formatting here |
|
✗ Repo Assist encountered failed, see workflow run. Warning Firewall blocked 6 domainsThe following domains were blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "api.nuget.org"
- "api.worldbank.org"
- "dc.services.visualstudio.com"
- "raw.githubusercontent.com"
- "schemas.microsoft.com"
- "tomasp.net"See Network Configuration for more information.
|
|
🤖 This is an automated response from Repo Assist. I investigated the Findings — this looks like a transient/flaky failure, not a real formatting issue:
Since I can't reproduce the failure and there's no actual formatting drift to fix, I haven't pushed a code change — that would be an unnecessary/unrelated diff. Re-running the Warning Firewall blocked 6 domainsThe following domains were blocked by the firewall during workflow execution:
To allow these domains, add them to the network:
allowed:
- defaults
- "api.nuget.org"
- "api.worldbank.org"
- "dc.services.visualstudio.com"
- "raw.githubusercontent.com"
- "schemas.microsoft.com"
- "tomasp.net"See Network Configuration for more information.
Add this agentic workflow to your repoTo install this agentic workflow, run |
🤖 This PR was created by Repo Assist, an automated AI assistant.
Problem
JsonSchema.validateconstructed a brand-newSystem.Text.RegularExpressions.Regexon every single string-value validation call when the schema had apatternconstraint:For a schema validating many values against the same pattern (e.g. array items, or the same property repeated across many objects), this recompiled the identical regex from scratch on every call — wasted CPU with no benefit, since the pattern string itself never changes for a given schema node.
Fix
Added a small
ConcurrentDictionary<string, Regex>cache (patternRegexCache) keyed by the pattern string, with agetPatternRegexhelper that compiles a pattern once and reuses it thereafter.validatenow callsgetPatternRegex patterninstead of constructing aRegexinline.Rationale / Trade-offs
ValidationResultoutputs.System.Collections.Concurrentis part of the BCL.Regexcached per distinct pattern string seen at runtime (schemas typically have a small, fixed set of patterns).ConcurrentDictionary, matching the library's existing use of aRegexper validation call site (previously recreated per-call, now created once).Test Status
dotnet run --project build/build.fsproj -t Build: ✅ succeeded, 0 errors (pre-existing warnings only, unrelated to this change)dotnet run --project build/build.fsproj -t CheckFormat: ✅ passed ("No files need formatting")dotnet test tests/FSharp.Data.Core.Tests/FSharp.Data.Core.Tests.fsproj --filter "FullyQualifiedName~JsonSchema": ✅ 43/43 passed, includingvalidate validates string patterndotnet run --project build/build.fsproj -t RunTests(full suite): ✅ 489 + 3143 + 2 tests passed, 0 failedAlso included
RELEASE_NOTES.mdentry (8.2.1) documenting the perf fix, per repository conventions.Warning
Firewall blocked 6 domains
The following domains were blocked by the firewall during workflow execution:
api.nuget.orgapi.worldbank.orgdc.services.visualstudio.comraw.githubusercontent.comschemas.microsoft.comtomasp.netTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run