Why is spdiags() much slower now than in previous versions

7 views (last 30 days)
I have used spdiags() over many years.
Lately MathWorks have updated the script and the response is much slower.
I have compared spdiags() from R2019a with R2021a on a mac.
The older spdiags() runs in my present test 15 to 40 times faster than the latest spdiags().
I wonder what benefit I get from waiting that much longer, for something that involves plugging numbers into a sparse matrix.
  7 Comments
Bruno Luong
Bruno Luong on 18 Apr 2023
@Brandon Caasenbrood "I can confirm the same. spdiags has poor performance compared to previous matlab version (e.g. 2021a outperforms 2023a signficantly)"
I just test the same code I posted above with R2023a, and it is faster than R2021a.
>> testspdiags
ans =
'9.14.0.2206163 (R2023a)'
Elapsed time is 0.153604 seconds. % REMINDER: Elapsed time is 0.188962 seconds. for R2021a
Brandon Caasenbrood
Brandon Caasenbrood on 19 Apr 2023
Edited: Brandon Caasenbrood on 19 Apr 2023
I might have shouted wolf too early. But I'm getting subpar performance with spdaig in comparison to speye when make diagonal matrices. I've recently moved from 2021a to 2023a, and only now noticed the performance dip; which made me believe the "6 May 2021" issue above was related. Consider the following code (a segment from the MMA solver by Krister Svanberg - https://gitlab.gbar.dtu.dk/s144426/s144426-TopOpt/-/blob/9e34bb5bb19b2e0f5aebbb4640f4d296627140d6/subsolv.m)
GG and GG_ are identical, but speye outperforms spdiags here. Nevertheless, running the below code, gives indeed similar performance. What am I missing here?
clc;
M = 3e4;
N = 1e3;
tic;
disp('test: spdiags');
a = rand(M,1);
for ii = 1:N
A = spdiags(a,0,M,M) - spdiags(a/10,0,M,M);
end
toc
tic;
disp('test: speye');
a = rand(M,1);
for ii = 1:N
A = a.*speye(M,M) - (a/10).*speye(M,M);
end
toc
% test: spdiags
% Elapsed time is 0.814878 seconds.
% test: speye
% Elapsed time is 0.847202 seconds.
The profiler says the bottleneck is in spdiags>makeSparseGeneral.Slightly odd, since I, J, and V are preallocated above, and I also never seen a profiler highlighting the iteration counter before.

Sign in to comment.

Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!