A .NET performance investigation reveals that sharing a compiled Regex instance across concurrent threads causes significant slowdowns — up to 6x — due to how the .NET Regex engine manages its internal RegexRunner state. The runner is checked out exclusively per call using Interlocked.Exchange, so concurrent callers must allocate new runner instances, causing heavy GC pressure. The issue affects both RegexOptions.Compiled and source-generated regexes. The workaround is to use ThreadLocal<Regex> to avoid concurrent access, at the cost of higher memory usage. A GitHub issue has been filed against the .NET runtime.
42.4K Impressions