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

performance regression on master for folds #48792

Open
matthias314 opened this issue Feb 26, 2023 · 0 comments
Open

performance regression on master for folds #48792

matthias314 opened this issue Feb 26, 2023 · 0 comments

Comments

@matthias314
Copy link
Contributor

This may be related to #48240. For the code below I get

julia> @btime f($v, $w)
  34.609 μs (0 allocations: 0 bytes)   # 1.9.0-beta4
  69.175 μs (0 allocations: 0 bytes)   # 1.10.0-DEV.658 Commit 129d45169b2 (0 days old master)

Here is the code. The type UnsafeArray is a wrapper that turns bounds-checking off.

import Base: parent, getindex, axes, IndexStyle, eachindex, unsafe_getindex

struct UnsafeArray{T,N,P<:AbstractArray{T,N}} <: AbstractArray{T,N}
    parent::P
end

getindex(a::UnsafeArray, ii...) = unsafe_getindex(a.parent, ii...)
axes(a::UnsafeArray, d...) = axes(a.parent, d...)
IndexStyle(a::UnsafeArray) = IndexStyle(a.parent)
eachindex(is::IndexStyle, a::UnsafeArray) = eachindex(is, a.parent)
size(a::UnsafeArray, d...) = size(a.parent, d...)

f(v, w) = mapfoldl(splat(*), +, zip(v, w); init = zero(eltype(v)))

v = rand(Int8, 2^16);
w = UnsafeArray(view(v, :));

There is no regression for f(v,v), but that expression is involved in a mystery. If on master I time f(v,v) before f(v,w), then I get a different result:

julia> @btime f($v, $v); @btime f($v, $w)
  40.393 μs (0 allocations: 0 bytes)   # same as on 1.9.0-beta4
  44.629 μs (0 allocations: 0 bytes)   # this has suddenly dropped!
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 4 × Intel(R) Core(TM) i3-10110U CPU @ 2.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-14.0.6 (ORCJIT, skylake)
  Threads: 1 on 4 virtual cores
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant