Skip to content

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

Open
Copilot wants to merge 3 commits intomainfrom
copilot/fix-hash-collisions-duplicate-data-row-analyzer
Open

Fix O(n²) hash collisions in DuplicateDataRowAnalyzer#7803
Copilot wants to merge 3 commits intomainfrom
copilot/fix-hash-collisions-duplicate-data-row-analyzer

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

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:

// Before
hashCode.Add(typedConstant.Kind);
hashCode.Add(SymbolEqualityComparer.Default.GetHashCode(typedConstant.Type));

// After
hashCode.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 path
    else
        hashCode.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:

Copilot AI requested review from Copilot and removed request for Copilot April 24, 2026 09:04
…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>
Copilot AI requested review from Copilot and removed request for Copilot April 24, 2026 09:10
Copilot AI changed the title [WIP] Fix O(n2) hash collisions in DuplicateDataRowAnalyzer Fix O(n²) hash collisions in DuplicateDataRowAnalyzer Apr 24, 2026
Copilot AI requested a review from Evangelink April 24, 2026 09:11
@Evangelink Evangelink marked this pull request as ready for review April 24, 2026 12:25
Copilot AI review requested due to automatic review settings April 24, 2026 12:25
@Evangelink Evangelink enabled auto-merge (squash) April 24, 2026 12:25
Copy link
Copy Markdown
Contributor

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

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
File Description
src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs Updates 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 thread src/Analyzers/MSTest.Analyzers/DuplicateDataRowAnalyzer.cs
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.

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

3 participants