Skip to content

Remove slow regex from threading analyzers#1547

Merged
AArnott merged 3 commits intomainfrom
dev/andarno/fixregextime
Feb 25, 2026
Merged

Remove slow regex from threading analyzers#1547
AArnott merged 3 commits intomainfrom
dev/andarno/fixregextime

Conversation

@AArnott
Copy link
Member

@AArnott AArnott commented Feb 25, 2026

Root cause: Both NegatableTypeOrMemberReferenceRegex and MemberReferenceRegex contained (?<typeName>[^\[\]\:]+)+ — a character-class group with an unnecessary outer + quantifier. When the overall match failed on a long type name, the regex engine tried exponentially many ways to split the type-name substring across the group, causing catastrophic backtracking.

Fix: Removed both Regex fields and RegexMatchTimeout entirely from CommonInterest.cs, replacing each call site with custom string parsers.

Also add an mcp.json file.

Copilot AI review requested due to automatic review settings February 25, 2026 16:15
@AArnott AArnott enabled auto-merge February 25, 2026 16:15
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes regex-based parsing from threading analyzers to avoid pathological backtracking/timeout scenarios and improve performance determinism.

Changes:

  • Removed regex fields (and timeout handling) used to parse additional-file entries.
  • Added non-regex parsers for type/member reference lines and updated call sites to use them.

@AArnott AArnott force-pushed the dev/andarno/fixregextime branch from a56023c to 13513b5 Compare February 25, 2026 16:34
Copilot AI review requested due to automatic review settings February 25, 2026 16:36
@AArnott AArnott force-pushed the dev/andarno/fixregextime branch from 13513b5 to 4abe4eb Compare February 25, 2026 16:36
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

@AArnott AArnott force-pushed the dev/andarno/fixregextime branch from 4abe4eb to 0df6788 Compare February 25, 2026 17:31
Copilot AI review requested due to automatic review settings February 25, 2026 18:31
@AArnott AArnott force-pushed the dev/andarno/fixregextime branch from 0df6788 to c4644e8 Compare February 25, 2026 18:31
@AArnott AArnott merged commit 34ec670 into main Feb 25, 2026
8 of 10 checks passed
@AArnott AArnott deleted the dev/andarno/fixregextime branch February 25, 2026 18:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

src/Microsoft.VisualStudio.Threading.Analyzers/CommonInterest.cs:91

  • SplitQualifiedIdentifier returns a non-null string type name, but the deconstruction uses string? typeName, which can trigger nullable warnings when passing typeName to QualifiedType (expects string). Consider deconstructing into string typeName (or otherwise ensure the value is statically non-null).
            (ImmutableArray<string> containingNamespace, string? typeName) = SplitQualifiedIdentifier(typeNameMemory);
            var type = new QualifiedType(containingNamespace, typeName);
            QualifiedMember member = memberNameValue is not null ? new QualifiedMember(type, memberNameValue) : default(QualifiedMember);

}
catch (RegexMatchTimeoutException)

(ImmutableArray<string> containingNamespace, string? typeName) = SplitQualifiedIdentifier(typeNameMemory);
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nullable flow issue here: SplitQualifiedIdentifier returns a non-null string, but you deconstruct into string? typeName and then pass it to QualifiedType, which may produce nullable warnings. Use a non-null string local (or apply a null-forgiving operator if truly intended).

This issue also appears on line 89 of the same file.

Suggested change
(ImmutableArray<string> containingNamespace, string? typeName) = SplitQualifiedIdentifier(typeNameMemory);
(ImmutableArray<string> containingNamespace, string typeName) = SplitQualifiedIdentifier(typeNameMemory);

Copilot uses AI. Check for mistakes.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.Threading.Analyzers;
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using Microsoft.VisualStudio.Threading.Analyzers; is redundant here because the test project already defines global using Microsoft.VisualStudio.Threading.Analyzers; in Usings.cs. Keeping both can cause unnecessary-using style diagnostics in some configurations.

Suggested change
using Microsoft.VisualStudio.Threading.Analyzers;

Copilot uses AI. Check for mistakes.
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.

3 participants