sparsemat / sprs

sparse linear algebra library for rust
Apache License 2.0
386 stars 45 forks source link

Add #[inline] to indexing #216

Closed mulimoen closed 4 years ago

mulimoen commented 4 years ago

Adding the #[inline] attribute to the indexing operators got a speedup of 15-30% on mul_acc_mat_vec_csr for some matrices. The benchmarks in this library does not gain or lose anything from this change.

Further observations: Changing to unsafe access in mul_acc_mat_vec_csr does not modify the performance characteristics compared to the safe version.

vbarrielle commented 4 years ago

That's a good change, these short functions are good candidates for inlining.

The benchmarks in this library does not gain or lose anything from this change.

I don't think they test mul_acc_mat_vec_csr, what's tested there uses iterators, so this explains why there's no difference.

Thanks for finding this!

mulimoen commented 4 years ago

@vbarrielle I would expect all functions using SparseVector to benefit from this, including the benched function dot_dense. It might be that it is inlined automatically inside the crate, but does not pass across the crate barrier.

vbarrielle commented 4 years ago

Yes that's very probable actually.