Improve performance of flatten in DenseMatrix#3400
Conversation
|
Thanks David. I've run the benchmark comparing |
|
Thanks for reviewing this Jos, let me check what happened and report back. |
|
Hi, I was missing a parenthesis. Was using Faster by 25% on my end, could you please validate? I think the initial improvement I was showing was comparing to develop before #3354 |
|
Thanks David, I get the same results as you when running the benchmark. I have a couple of thoughts:
|
|
Hi Jos! Thank you for reviewing this!
I will make a new benchmark between arrays including your example, compare using I completely understand if in the end the added complexity of a second algorithm isn't worth it. I expect something positive from comparing apples to apples on the following days. |
|
Hi Jos, I included a new commit, with your code proposal for regular arrays and modified the code for rectangular arrays to take a boolean as an argument instead of the maximum depth.
As a summary your code proposal is 36% faster than dev for arrays in general, for rectangular arrays the specialized algorithm shows 52% improvement. As you mentioned the improvement is lost in the creation of a Matrix, in the end it improves 18%. I tested your proposed algorithm for arrays in general using it also for matrices and the improvement is 14% (instead of 18%). Compared to the previous commit, with changes only in the algorithm for rectangular arrays but using
It had the same 52% improvement, I think just by luck it shows 21% improvement for Matrices (vs 18% of the new commit) A nice improvement of using a boolean indicating if it's rectangular, is that you don't need to know the size of the array, just that it is rectangular, as it's the case for the function My conclusions:
|
|
Thanks for the updates David!
I think this PR is ready to merge, agree? |
|
Thanks! Yes I agree this is ready to merge, just renamed "homogeneous" to "rectangular" and found a case in |
|
Please wait, I found a possible regression. |
|
All good, this is ready to merge. |
|
👍 thanks again David |
|
Published now in |

Hi, this improves the performance of flattening matrices by 60%.