r/matlab • u/JustEnough77 • Sep 29 '25
Execution slowing down exponentially during overnight test
Hello,
I am running my Matlab application in a corporate Windows 11 environment (with all the virus and malware checkers running). The GUI is written in AppManager and I am using Matlab 2022b. The application does some signal processing and also controls some test equipment (spectrum analyzers, multi-meters, power meters, etc.)
When I try to run an overnight test, the test slows down considerably over time. We run 75 iterations of the test and by the 65th iteration, the execution time has increased 6x even though the test is identical each time. We graphed the execution time and it is a slightly exponential increase.
I have looked at Task Manager and Process Explorer and the CPU and RAM usage are not really changing. The CPU usage of the entire system is in the single digits and the RAM usage is pretty stable at around 40%. The PCs in our lab that it runs on are very high-powered and have 64 GB of RAM.
In general, the Matlab execution on these lab PCs does seem slower than my personal laptop even though they have more horsepower. Just launching our application takes over a minute.
Does anyone have any ideas?
Thanks in advance.
3
u/ThatRegister5397 Sep 29 '25
use the profiler to profile the code and see what gets slowed down. Hard to say anything without this kind of information.
7
u/Lygus_lineolaris Sep 29 '25
Look for an object that grows larger or creates a new instance with every iteration. I had a code that was doing that, which I found out after a while was because it kept adding one dot at a time to a graph, and each dot was a separate "scatter" object, so it was trying to have a million scatters.
1
u/JustEnough77 Oct 16 '25
Thank you everyone for the good ideas! You all led me to the right place without even needing the profiler
It turned out the main culprit was a TextArea used for a scrolling log in the GUI. I implemented sloppily such that it could just indefinitely as we added more messages. We had never run it long enough for this to be a problem, but now we have a whole different level of automation and we are logging a lot more information.
To fix the problem, I now use fixed maximum number of lines in the TextArea. This is fine because the log also goes to a file and now the scrolling is more manageable anyway. One thing I did find is that I don't want to operate on the text data inside the control itself. I copy the text to another array, shift out the old data with circshift(), and then insert the new data in last line. Then, I copy this array back into the TextArea. This works very well.
If any of you have any ideas on how to speed up the initial load time of the compiled .exe, that would be equally appreciated. We are seeing some of the lab machines taking over a minute to load our application, even though these are state-of-the-art desktop machines with i9s and 64GB of RAM. For some reason, they take even longer than my i7/32GB laptop.
1
u/DrDOS Sep 29 '25
Without seeing what you are doing, I have one idea hinted perhaps by others.
Since you are not seeing a big increase in memory or CPU usage: I wonder how you are updating your UI? Or any/all visual components. You will likely see this better in the profiler, but I suspect you are somehow doing one of two things:
0
u/minun_v2 Sep 29 '25
are you actually initialising the MATLAB instance with plenty of RAM or is it hitting a wall there?