Skip to content

Fix O(n²) hash collisions in DuplicateDataRowAnalyzer - #7803

Merged
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/fix-hash-collisions-duplicate-data-row-analyzer
Apr 27, 2026
Merged

Fix O(n²) hash collisions in DuplicateDataRowAnalyzer#7803
Amaury Levé (Evangelink) merged 3 commits into
mainfrom
copilot/fix-hash-collisions-duplicate-data-row-analyzer

Conversation

CopilotAI commented Apr 24, 2026

Copy link
Copy Markdown
Contributor

TypedConstantArrayComparer.GetHashCode only hashed Kind and Type, ignoring Value. This caused all [DataRow(T)] attributes sharing the same parameter type to produce identical hashes, degrading every dictionary lookup to O(n) and making duplicate detection O(n²).

Change

Include Value in the hash, matching the logic already present in Equals:

// BeforehashCode.Add(typedConstant.Kind);hashCode.Add(SymbolEqualityComparer.Default.GetHashCode(typedConstant.Type));// AfterhashCode.Add(typedConstant.Kind);hashCode.Add(SymbolEqualityComparer.Default.GetHashCode(typedConstant.Type));if(!typedConstant.IsNull){if(typedConstant.Kind==TypedConstantKind.Array)hashCode.Add(GetHashCode(typedConstant.Values));// recursive, matches Equals pathelsehashCode.Add(typedConstant.Value);}
  • Null values are skipped (consistent with Equals null-handling).
  • Array-typed constants are recursively hashed to match the recursive Equals path.
  • Restores O(n) behaviour for the common case of multiple [DataRow] attributes on a single test method.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/testfx/testfx/artifacts/bin/MSTest.Analyzers.UnitTests/Release/net8.0/MSTest.Analyzers.UnitTests /home/REDACTED/work/testfx/testfx/artifacts/bin/MSTest.Analyzers.UnitTests/Release/net8.0/MSTest.Analyzers.UnitTests --diagnostic --diagnostic-output-directory /home/REDACTED/work/testfx/testfx/artifacts/log/Release --diagnostic-file-prefix MSTest.Analyzers.UnitTests_net8.0_Release_x64 --diagnostic-verbosity trace --crashdump --hangdump --hangdump-timeout 15m --report-azdo --coverage --coverage-settings /home/REDACTED/work/testfx/testfx/test/coverage.config --coverage-output MSTest.Analyzers.UnitTests_net8.0_Release_x64.coverage --filter DuplicateDataRow (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

…lue in GetHashCode
Agent-Logs-Url: https://github.com/microsoft/testfx/sessions/2135dfb7-7ef6-4958-953f-5384259bfc39
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
CopilotAI requested review from Copilot and removed request for CopilotApril 24, 2026 09:10
CopilotAI changed the title [WIP] Fix O(n2) hash collisions in DuplicateDataRowAnalyzerFix O(n²) hash collisions in DuplicateDataRowAnalyzerApr 24, 2026
@Evangelink
Amaury Levé (Evangelink) marked this pull request as ready for review April 24, 2026 12:25
CopilotAI review requested due to automatic review settings April 24, 2026 12:25

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Improves DuplicateDataRowAnalyzer performance by strengthening hashing for [DataRow] constructor arguments so dictionary lookups don’t degrade due to excessive hash collisions.

Changes:

  • Extend TypedConstantArrayComparer.GetHashCode to incorporate TypedConstant.Value when non-null.
  • Recursively hash array-typed constants to mirror the recursive equality logic.
Show a summary per file
FileDescription
src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.csUpdates hashing logic for typed constants (including arrays) to reduce collisions and improve analyzer performance.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 1

Comment threadsrc/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs
@Evangelink
Amaury Levé (Evangelink) merged commit 76e137b into mainApr 27, 2026
10 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the copilot/fix-hash-collisions-duplicate-data-row-analyzer branch April 27, 2026 07:23
Sign up for freeto 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.

[Efficiency Improver] Fix O(n2) hash collisions in DuplicateDataRowAnalyzer

4 participants

@JanKrivanek@Evangelink