diff --git a/Project.toml b/Project.toml index f512105..17d8e2e 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "GroupedArrays" uuid = "6407cd72-fade-4a84-8a1e-56e431fc1533" authors = ["matthieugomez "] -version = "0.3.5" +version = "0.3.6" [deps] DataAPI = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" diff --git a/src/spawn.jl b/src/spawn.jl index f6a11df..2daf9a3 100644 --- a/src/spawn.jl +++ b/src/spawn.jl @@ -30,13 +30,18 @@ function _spawn_for_chunks_helper(iter, lbody, basesize) nt = Threads.nthreads() len = length(x) if nt > 1 && len > basesize - tasks = [@spawn begin - for i in p - local $(esc(lidx)) = @inbounds x[i] - $(esc(lbody)) - end - end - for p in split_indices(len, basesize)] + # a loop rather than a comprehension: collecting the generator compiles + # abstractly typed Base code that packages adding array methods + # (e.g. CategoricalArrays) invalidate + tasks = Task[] + for p in split_indices(len, basesize) + push!(tasks, @spawn begin + for i in p + local $(esc(lidx)) = @inbounds x[i] + $(esc(lbody)) + end + end) + end foreach(wait, tasks) else for i in eachindex(x) diff --git a/src/utils.jl b/src/utils.jl index 7cc78b4..bb0f8cf 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -317,7 +317,16 @@ function row_group_slots!(cols::NTuple{N, AbstractVector}, newcols, refpools, refarrays, hash, groups, skipmissing, sort, compress) end - strides = (cumprod(collect(reverse(ngroupstup)))[end-1:-1:1]..., 1)::NTuple{N, Int} + # strides[i] is the product of ngroupstup[i+1:N]. Computed with a loop rather than + # cumprod(collect(reverse(ngroupstup))), which compiles abstractly typed Base code + # that packages adding array methods (e.g. CategoricalArrays) invalidate + strides = ntuple(Val(N)) do i + stride = 1 + for j in (i + 1):N + stride *= ngroupstup[j]::Int + end + stride + end firstinds = map(firstindex, refpools) if sort nminds = map(refpools, missinginds) do refpool, missingind