Skip to content

attribute: make TestHashKVs linear-time#8204

Merged
pellared merged 4 commits intoopen-telemetry:mainfrom
pellared:speedup-hash-test
Apr 15, 2026
Merged

attribute: make TestHashKVs linear-time#8204
pellared merged 4 commits intoopen-telemetry:mainfrom
pellared:speedup-hash-test

Conversation

@pellared
Copy link
Copy Markdown
Member

@pellared pellared commented Apr 14, 2026

Unblocks #8166

Per #8166 (comment)

Why

This updates TestHashKVsEquality to avoid the quadratic pairwise comparison that was causing slow runs and timeouts in CI.

Below are the results from my machine.

Old:

$ go test -run=TestHashKVs -count=1 
PASS
ok      go.opentelemetry.io/otel/attribute      2.063s

New:

$ go test -run=TestHashKVs -count=1 
PASS
ok      go.opentelemetry.io/otel/attribute      0.024s

Instead of collecting every generated testcase and comparing each hash against every other hash, the test now checks uniqueness as each case is generated by storing previously seen hashes in a map. Note that it also does not use the equality operator of KeyValue to determine if the hash should be equal or different.

What

  • Rename the test from TestHashKVsEquality to TestHashKVs
  • Replace the O(n^2) post-processing loop with an O(n) streaming uniqueness check
  • Simplify failure reporting by removing the dedicated msg helper

Side note: for me it also makes the test more readable (however, this is opinionated).

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 14, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.3%. Comparing base (3ee1d5a) to head (6d8095d).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff          @@
##            main   #8204   +/-   ##
=====================================
  Coverage   82.3%   82.3%           
=====================================
  Files        310     310           
  Lines      24266   24266           
=====================================
+ Hits       19985   19986    +1     
+ Misses      3904    3903    -1     
  Partials     377     377           

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pellared pellared added the Skip Changelog PRs that do not require a CHANGELOG.md entry label Apr 14, 2026
@pellared pellared marked this pull request as ready for review April 14, 2026 21:31
@pellared pellared merged commit fbbc5a6 into open-telemetry:main Apr 15, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Skip Changelog PRs that do not require a CHANGELOG.md entry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants