Skip to content

Commit fd8f075

Browse files
committed
typekey_hash: length-independent run time for hashing long Vararg
I'm not familiar with the C code, and I'm not sure this change is correct, but playing with it in the REPL doesn't reveal any obvious bugs. Prior to this change, the run time of an operation like `Tuple{Vararg{T, 1000000}} where {T}` scales linearly with the field count (1000000 in this example). The goal of this change is to make the run time be independent from the field count. The idea is to simply return the same hash for all field counts greater than or equal to a cut off. Follows up on PR JuliaLang#50932, which introduced the loop linear in the field count.
1 parent 04922e7 commit fd8f075

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/jltypes.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,9 @@ static unsigned typekey_hash(jl_typename_t *tn, jl_value_t **key, size_t n, int
18051805
unsigned hashp = type_hash(p, &failed);
18061806
if (failed && !nofail)
18071807
return 0;
1808+
size_t vararg_length_hash_precision_cutoff = 100000; // don't spend too much time hashing long Vararg
1809+
if (vararg_length_hash_precision_cutoff < repeats)
1810+
repeats = vararg_length_hash_precision_cutoff;
18081811
while (repeats--)
18091812
hash = bitmix(hashp, hash);
18101813
}

0 commit comments

Comments
 (0)