Converting symbolic to MATLAB functions became 30x slower from R2018b to R2020a

3 views (last 30 days)
I have code that converts a vector-valued 16x1 symbolic function of 50 variables into a MATLAB function stored in a file:
fxout=matlabFunction(fx,'Vars',order,'File','fxfun');
In R2018b, this ran in less than 2 seconds. In R2020a, to which I just upgraded, it takes 63 seconds. I profiled both and the difference is entirely in the execution time of mupadmex, a MEX file the contents of which obviously don't get profiled. The number of calls to mupadmex is higher in R2020a too, but by 25% or so, not by 30x.
I read the Symbolic Toolbox release notes for the last few versions and nothing jumps out at me as an explanation for this.
Anyone have any ideas? I don't even know where to start... I get that this should take a bit of time since it's a complex operation. I'm ok with 2 seconds. I'm not ok with 60+ seconds, especially since I need to do a similar operation for a much larger function, which used to take 2 minutes, and, if this scales linearly, would now take 1 hour.

Accepted Answer

Paul Williams
Paul Williams on 18 Aug 2020
A colleague had a similar issue with symbolic toolbox between R2018 and R2019b. I investigated this and found that the degradation happens as of R2019a Update 4. This is due to a change in the lib.tar (toolbox\symbolic\mupad\lib). Inside the tar, a function was changed that optimizes the symbolic expressions. A special case was added for single input expressions in 2019a Update 4. Specifically, GENERATE\optimize.mu, commenting out the line:
equations[k+1..-1] := flattenOneArgFunctions(equations[k+1..-1]);
and re-taring the lib file restored the pre-update performance.
  3 Comments
Vadim Elenev
Vadim Elenev on 18 Aug 2020
Confirming that Paul's solution works. Rik, how does one go about submitting such a report?
Rik
Rik on 18 Aug 2020
I presume by filling out the contact form, or by filing a bug report (I believe you can choose to label it as an enhancement request instead of a bug).
Alternatively you could send an email to a Mathworks employee you may have had contact with and ask them to forward it to the correct department. But filling out the contact form is clearly more polite.

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!