Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve channel_unordered performance: Take items from input channel outside worker threads #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/unordered.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,22 @@ function transduce_commutative!(
)
@argcheck ntasks > 0
@argcheck basesize > 0
rf = reducingfunction(xform, step; simd = simd)
rf = reducingfunction(Cat() |> xform, step; simd = simd)
stop = Threads.Atomic{Bool}(false)
tasks = map(1:ntasks) do _
@spawn try
@async try
acc′ = _start_init(rf, init)
finished = false
xs = Union{}[]
while !finished
xs = append!!(empty!(xs), Iterators.take(input, basesize))
isempty(xs) && return acc′
acc′, finished = let acc′′ = acc′
@spawn begin
acc = acc′′
for _ in 1:basesize
x = maybe_popfirst!(input)
x === nothing && return acc, true
acc = next(rf, acc, something(x))
if isreduced(acc)
stop[] = true
return acc, true
end
acc = next(rf, acc′′, xs)
if isreduced(acc)
stop[] = true
return acc, true
end
return acc, false
end
Expand Down