Broadcasting is much slower than a for loop
Open
Nobody has claimed this yet.
broadcast
compiler:simd
performance
regression
- Dominant language
- Julia
- Stars
- 49.1k
- Forks
- 6k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 209
Description
Here is a minimal working example.
julia> using BenchmarkTools
julia> function foo(a::Vector{T}, b::Vector{T}, c::Vector{T}, d::Vector{T}, e::Vector{T}) where T
@. a = b + 0.1 * (0.2c + 0.3d + 0.4e)
nothing
end
foo (generic function with 1 method)
julia> function goo(a::Vector{T}, b::Vector{T}, c::Vector{T}, d::Vector{T}, e::Vector{T}) where T
@assert length(a) == length(b) == length(c) == length(d) == length(e)
@inbounds for i in eachindex(a)
a[i] = b[i] + 0.1 * (0.2c[i] + 0.3d[i] + 0.4e[i])
end
nothing
end
goo (generic function with 1 method)
julia> a,b,c,d,e=(rand(1000) for i in 1:5)
Base.Generator{UnitRange{Int64},getfield(Main, Symbol("##9#10"))}(getfield(Main, Symbol("##9#10"))(), 1:5)
julia> @btime foo($a,$b,$c,$d,$e)
1.277 μs (0 allocations: 0 bytes)
julia> @btime goo($a,$b,$c,$d,$e)
345.568 ns (0 allocations: 0 bytes)
julia> versioninfo()
Julia Version 0.7.0-beta2.12
Commit a878341 (2018-07-15 15:57 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
JULIA_PKG3_PRECOMPILE = 1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No source files or tests are named. Start by reproducing the Julia 0.7 benchmark comparing foo's broadcast expression with goo's @inbounds loop, then inspect the broadcasting implementation and benchmark coverage; done means the broadcasted operation no longer has the reported performance gap and a regression test or benchmark captures it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- performance
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100