JuliaArrays / AxisArrays.jl

Performant arrays where each dimension can have a named axis with values
http://JuliaArrays.github.io/AxisArrays.jl/latest/
Other
200 stars 41 forks source link

significant performance regression versus 0.3.0 #169

Closed colinxs closed 5 years ago

colinxs commented 5 years ago
x=rand(3,3)
a=AxisArray(x, [:x,:y,:z], [:foo1, :foo2, :foo3])
@btime $a[:x, :foo1]

v0.3.0: 5.115 ns (0 allocations: 0 bytes) v0.3.1 and v0.3.2 294.645 ns (3 allocations: 80 bytes)

versioninfo:

Julia Version 1.1.1
Commit 55e36cc308 (2019-05-16 04:10 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)
c42f commented 5 years ago

Darn, this is probably due to the trait refactoring I did in #163.

c42f commented 5 years ago

Does #170 fix this for your real use case?

colinxs commented 5 years ago

It looks like #170 fixes the above. Thanks for the quick fix!

Unfortunately I'm still running into a few performance issues when slicing. I think these aren't new, however (tested with v0.3.0 as well as #170)

x=rand(3,3)
y=rand(3)
a=AxisArray(x, [:x,:y,:z], [:foo1, :foo2, :foo3])
au=AxisArray(uview(x), [:x,:y,:z], [:foo1, :foo2, :foo3])
# With AxisArrays
@btime $y .= view($a, :x, :)
  # 500.005 ns (3 allocations: 96 bytes)
@btime $y .= view($au, :x, :)
  # 357.435 ns (2 allocations: 96 bytes)
@btime $y .= view($au, 1, :)
  # 358.857 ns (2 allocations: 96 bytes)
@btime $y .= $au[:, 1]
  # 275.429 ns (3 allocations: 160 bytes)

# Without AxisArrays
@btime $y .= view($x, 1, :)
  # 15.149 ns (1 allocation: 48 bytes)
 @btime $y .= uview($x, 1, :)
  # 14.594 ns (0 allocations: 0 bytes)
@btime $y .= $x[:, 1]
  # 29.032 ns (1 allocation: 112 bytes)

So it appears that any kind of slicing, with or without view and integer indexing, is quite a bit slower.

c42f commented 5 years ago

Symbol-based indexing will always have a performance hit of some kind.

I'm not so sure whether the integer slicing performance hit relative to normal arrays is expected — feel free to open a separate issue for that if you like.

timholy commented 5 years ago

What's uview?

colinxs commented 5 years ago

They are stack-allocated array views from UnsafeArrays.jl. They are quite useful for getting maximally performant code.

Colin X Summers University of Washington Personal Robotics Lab www.colinxsummers.com

On Sat., 31 Aug. 2019, 04:47 Tim Holy, notifications@github.com wrote:

What's uview?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JuliaArrays/AxisArrays.jl/issues/169?email_source=notifications&email_token=AELLS2EEWZNYHNPXANF265LQHJK6JA5CNFSM4IRZ64F2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD5TLGAI#issuecomment-526824193, or mute the thread https://github.com/notifications/unsubscribe-auth/AELLS2CB6JPPP7UDEJX2M6DQHJK6JANCNFSM4IRZ64FQ .

c42f commented 5 years ago

I bumped the project version to 0.3.3 so we can have this bug fixed.

@JuliaRegistrator register

JuliaRegistrator commented 5 years ago

Registration pull request created: JuliaRegistries/General/3239

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if Julia TagBot is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.3 -m "<description of version>" 316abc8c84591693ed427eef5f789884c0f468f9
git push origin v0.3.3