Skip to content

Commit a76de9e

Browse files
authored
move some allocations out of hot loop in the graph simplification in the resolver (#4474)
1 parent 7fad682 commit a76de9e

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

src/Resolve/graphtype.jl

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,12 @@ function propagate_constraints!(graph::Graph, sources::Set{Int} = Set{Int}(); lo
10831083
sources
10841084

10851085
seen = copy(staged)
1086+
staged_next = Set{Int}()
1087+
1088+
# Pre-allocate workspace for added constraints
1089+
max_spp = maximum(spp, init = 0)
1090+
added_constr1 = BitVector(undef, max_spp)
1091+
old_gconstr1 = BitVector(undef, max_spp)
10861092

10871093
while !isempty(staged)
10881094
staged_next = Set{Int}()
@@ -1097,16 +1103,28 @@ function propagate_constraints!(graph::Graph, sources::Set{Int} = Set{Int}(); lo
10971103
pkgs[p1] == uuid_julia && continue
10981104

10991105
msk = gmsk[p0][j1]
1100-
# consider the sub-mask with only allowed versions of p0
1101-
sub_msk = msk[:, gconstr0]
11021106
# if an entire row of the sub-mask is false, that version of p1
11031107
# is effectively forbidden
11041108
# (this is just like calling `any` row-wise)
1105-
added_constr1 = any!(BitVector(undef, spp[p1]), sub_msk)
1109+
# sub_msk = msk[:, gconstr0]
1110+
# added_constr1 = any!(BitVector(undef, spp[p1]), sub_msk)
1111+
# The code below is equivalent to the shorter code above, but avoids allocating
1112+
spp1 = spp[p1]
1113+
resize!(added_constr1, spp1)
1114+
fill!(added_constr1, false)
1115+
for v1 in 1:spp1
1116+
for v0 in 1:spp[p0]
1117+
if gconstr0[v0] && msk[v1, v0]
1118+
added_constr1[v1] = true
1119+
break
1120+
end
1121+
end
1122+
end
1123+
11061124
# apply the new constraints, checking for contradictions
11071125
# (keep the old ones for comparison)
11081126
gconstr1 = gconstr[p1]
1109-
old_gconstr1 = copy(gconstr1)
1127+
copy!(old_gconstr1, gconstr1)
11101128
gconstr1 .&= added_constr1
11111129
# if the new constraints are more restrictive than the
11121130
# previous ones, record it and propagate them next

0 commit comments

Comments
 (0)