Skip to content

Remove redundant one-argument hash(::TrackedReal) method - #322

Merged
devmotion merged 1 commit into
JuliaDiff:masterfrom
KristofferC:kc/fewer-invalidations
Oct 13, 2026
Merged

devmotion merged 1 commit into
JuliaDiff:masterfrom
KristofferC:kc/fewer-invalidations

Conversation

@KristofferC

@KristofferC KristofferC commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

I saw a number of invalidations stemming from this definition in a ReverseDiff workload.

hash(t::TrackedReal) = hash(value(t)) gives the same result as Base's generic hash(x) = hash(x, HASH_SEED) combined with the two-argument hash(::TrackedReal, ::UInt) that ReverseDiff already defines. Being more specific, it invalidates hash(::Any) callers (e.g. Dict rehashing) when the package loads.

On a small gradient workload (using ReverseDiff; ReverseDiff.gradient(x -> sum(abs2, x), rand(10))) on Julia master (with the Base invalidation fixes from the JuliaLang/julia kc/ttfx-invalidations branch) this takes the invalidated method instances from 932 to 763, and the ones that actually get re-inferred from 91 to 37.

🤖 Generated with Claude Code

It matches what Base's `hash(x) = hash(x, HASH_SEED)` fallback already
does through the two-argument method, and invalidates `hash(::Any)`
callers (e.g. `Dict` rehashing) on package load.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.37%. Comparing base (b796032) to head (b93d6b3).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #322      +/-   ##
==========================================
- Coverage   89.38%   89.37%   -0.01%     
==========================================
  Files          19       19              
  Lines        1978     1977       -1     
==========================================
- Hits         1768     1767       -1     
  Misses        210      210              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

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

@devmotion
devmotion merged commit a2d984e into JuliaDiff:master Oct 13, 2026
8 checks passed
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.

2 participants