@@ -338,46 +338,53 @@ function row_group_slots(cols::NTuple{N, AbstractVector},
338338 end
339339 refmap
340340 end
341- @inbounds for i in eachindex (groups)
342- local refs_i
343- let i= i # Workaround for julia#15276
344- refs_i = map (c -> c[i], refarrays)
345- end
346- vals = map ((m, r, s, fi) -> m[r- fi+ 1 ] * s, refmaps, refs_i, strides, firstinds)
347- j = sum (vals) + 1
348- # x < 0 happens with -1 in refmap, which corresponds to missing
349- if skipmissing && any (x -> x < 0 , vals)
350- j = 0
351- else
352- seen[j] = true
341+ tforeach (eachindex (groups), basesize= 1_000_000 ) do i
342+ @inbounds begin
343+ local refs_i
344+ let i= i # Workaround for julia#15276
345+ refs_i = map (c -> c[i], refarrays)
346+ end
347+ vals = map ((m, r, s, fi) -> m[r- fi+ 1 ] * s, refmaps, refs_i, strides, firstinds)
348+ j = sum (vals) + 1
349+ # x < 0 happens with -1 in refmap, which corresponds to missing
350+ if skipmissing && any (x -> x < 0 , vals)
351+ j = 0
352+ else
353+ seen[j] = true
354+ end
355+ groups[i] = j
353356 end
354- groups[i] = j
355357 end
356358 else
357- @inbounds for i in eachindex (groups)
358- local refs_i
359- let i= i # Workaround for julia#15276
360- refs_i = map (refarrays, missinginds) do ref, missingind
361- r = Int (ref[i])
362- if skipmissing
363- return r == missingind ? - 1 : (r > missingind ? r- 1 : r)
364- else
365- return r
359+ tforeach (eachindex (groups), basesize= 1_000_000 ) do i
360+ @inbounds begin
361+ local refs_i
362+ let i= i # Workaround for julia#15276
363+ refs_i = map (refarrays, missinginds) do ref, missingind
364+ r = Int (ref[i])
365+ if skipmissing
366+ return r == missingind ? - 1 : (r > missingind ? r- 1 : r)
367+ else
368+ return r
369+ end
366370 end
367371 end
372+ vals = map ((r, s, fi) -> (r- fi) * s, refs_i, strides, firstinds)
373+ j = sum (vals) + 1
374+ # x < 0 happens with -1, which corresponds to missing
375+ if skipmissing && any (x -> x < 0 , vals)
376+ j = 0
377+ else
378+ seen[j] = true
379+ end
380+ groups[i] = j
368381 end
369- vals = map ((r, s, fi) -> (r- fi) * s, refs_i, strides, firstinds)
370- j = sum (vals) + 1
371- # x < 0 happens with -1, which corresponds to missing
372- if skipmissing && any (x -> x < 0 , vals)
373- j = 0
374- else
375- seen[j] = true
376- end
377- groups[i] = j
378382 end
379383 end
380- if ! all (seen) # Compress group indices to remove unused ones
384+ # If some groups are unused, compress group indices to drop them
385+ # sum(seen) is faster than all(seen) when not short-circuiting,
386+ # and short-circuit would only happen in the slower case anyway
387+ if sum (seen) < length (seen)
381388 oldngroups = ngroups
382389 remap = zeros (Int, ngroups)
383390 ngroups = 0
0 commit comments