Skip to content

Conversation

@KristofferC
Copy link
Member

This changes the anonymous functions used in the calls to fkeep! made by droptol!, dropzeros!, triu! and tril! to instead use functors.

Performance differences below are with this benchmark:

A = sprand(10^5, 10^5, 0.001)
B = copy(A)

import Base.droptol!
import Base.dropzeros!

B = copy(A);
@time droptol!(B, 0.1);

B = copy(A);
@time dropzeros!(B);

B = copy(A);
@time triu!(B);

B = copy(A);
@time tril!(B);

Master

 605.263 milliseconds (49914 k allocations: 762 MB, 7.72% gc time)
 422.887 milliseconds (29908 k allocations: 456 MB, 8.26% gc time)
 376.937 milliseconds (29908 k allocations: 456 MB, 9.14% gc time)
 374.099 milliseconds (29908 k allocations: 456 MB, 9.38% gc time)

PR

  32.674 milliseconds (4 allocations: 144 bytes)
  31.266 milliseconds (4 allocations: 144 bytes)
  26.735 milliseconds (38 allocations: 2416 bytes)
  27.053 milliseconds (38 allocations: 2416 bytes)

@ssfrr
Copy link
Contributor

ssfrr commented Jun 12, 2015

Wow, super improvement. Is there any documentation on this technique, perhaps it could live in the Performance Tips section of the docs? I found a couple discussions of similar things in the julia-users list and I see some places where it's used in base but I'm having trouble piecing together exactly what's going on and how/why it's different from just defining the functions as functions.

@KristofferC
Copy link
Member Author

The README in https://github.com/lindahua/NumericFuns.jl has a little info about functors and why they sometimes (currently) are needed in Julia.

@dmbates
Copy link
Member

dmbates commented Jun 12, 2015

Great idea. When I wrote that section of csparse.jl I was imitating the C code and wasn't aware of Functors. Obviously this is a good use of Functors.

@ViralBShah
Copy link
Member

The sparse function already does the same too. Great idea. Can merge once appveyor completes.

@ViralBShah ViralBShah added the sparse Sparse arrays label Jun 12, 2015
@KristofferC
Copy link
Member Author

@ViralBShah Funny coincidence, I made the issue on the previously used anonymous functions in sparse #10694.

At that point I didn't know enough Julia to fix it myself though.

@KristofferC
Copy link
Member Author

Tests passing so should be fine to merge.

ViralBShah added a commit that referenced this pull request Jun 14, 2015
Performance improvements for sparse triu!, tril!, dropzeros!, droptol!
@ViralBShah ViralBShah merged commit 0497967 into JuliaLang:master Jun 14, 2015
@KristofferC KristofferC deleted the kc/functs_triu_etc branch August 4, 2015 16:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sparse Sparse arrays

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants