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

Speed up BitArray packing #13946

Merged
merged 3 commits into from
Nov 13, 2015
Merged

Speed up BitArray packing #13946

merged 3 commits into from
Nov 13, 2015

Conversation

carlobaldassi
Copy link
Member

Addresses #13914.

@tkelman
Copy link
Contributor

tkelman commented Nov 11, 2015

this is the kind of thing we should try and track perf for, ref #13893

@jakebolewski jakebolewski added the kind:potential benchmark Could make a good benchmark in BaseBenchmarks label Nov 11, 2015
@carlobaldassi carlobaldassi changed the title Inline set_index!(::BitArray, ::Any, ::Int) Speed up BitArray packing Nov 12, 2015
Changes in convert(::BitArray, ::AbstractArray) and
dumpbitcache():
* avoid branches in for loops
* pack 8 Bools at a time
* use inbounds
@carlobaldassi
Copy link
Member Author

I managed to speed up the whole process of BitArray packing.
Example:

a = rand(1:5, 300, 200);

julia> b = 2;

julia> function bcmp(n, a, b)
           for _ = 1:n
               a .!= b
           end
       end;

julia> function cmp(n, a, b)
           for _ = 1:n
               o = Array(Bool, size(a))
               for i in eachindex(a)
                   o[i] = a[i] != b
               end
            end
       end;

Timings:
on julia-0.4:

julia-0.4> @time bcmp(10_000, a, b)
  2.066846 seconds (41.74 k allocations: 113.155 MB, 0.56% gc time)

julia-0.4> @time cmp(10_000, a, b)
  0.407888 seconds (34.97 k allocations: 573.515 MB, 2.91% gc time)

with this PR:

julia-0.5> @time bcmp(10_000, a, b)
  0.675820 seconds (341.83 k allocations: 124.603 MB, 1.14% gc time)

julia-0.5> @time cmp(10_000, a, b)
  0.407919 seconds (34.30 k allocations: 573.476 MB, 3.04% gc time)

If everything works, and after some grace period, this could also be backported.

this is the kind of thing we should try and track perf for, ref #13893

Yes, definitely.

@carlobaldassi carlobaldassi added the performance Must go faster label Nov 12, 2015
@carlobaldassi
Copy link
Member Author

Also, a ~2x speedup in unsafe_setindex! by avoiding branching.

@timholy
Copy link
Sponsor Member

timholy commented Nov 12, 2015

Very impressive!

carlobaldassi added a commit that referenced this pull request Nov 13, 2015
@carlobaldassi carlobaldassi merged commit 8866b4e into master Nov 13, 2015
@tkelman tkelman deleted the cb/bit_inline_setindex branch November 13, 2015 06:03
@JeffBezanson
Copy link
Sponsor Member

Nice!

carlobaldassi added a commit that referenced this pull request Nov 29, 2015
Addresses #13914

(cherry picked from commit 73242ec)
ref #13946
jrevels added a commit to JuliaCI/BaseBenchmarks.jl that referenced this pull request Jan 27, 2016
@jrevels jrevels removed the kind:potential benchmark Could make a good benchmark in BaseBenchmarks label Jan 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Must go faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants