Code in live script run much slow

86 次查看(过去 30 天)
The new matlab live script functionality is really awesome, thanks matlab team.
But I observe that my code run considerably slower in live script than in the command line. Just out of curiousity, is this an expected result for a newly created function or there is some way to configure the amount of resource allocation for live script? Thanks.
  5 个评论
per isakson
per isakson 2020-8-7
编辑:per isakson 2020-8-7
Executions of functions are not affected as far as I can see on R2018b.
I copied the code of the comment above by Lukas Müller into an ordinary m-function and a Live Editor mlx-function. tic/toc reports the same elapse time for the two
>> live_function_test
Elapsed time is 0.145617 seconds.
>> live_function_test_LE % Live Editor
Elapsed time is 0.143375 seconds.
P.S. I did a similar comparison with scripts. The m-script finished in about the same time as the functions. I interupted the live-script after a minute.
feynman feynman
feynman feynman 2024-2-8
"
Code in live script run much slow
" is this talking about live script on a local pc (offline) or online? Is running offline still much slower than in m files?

请先登录,再进行评论。

采纳的回答

Philip
Philip 2020-3-5
编辑:Philip 2020-10-14
This issue has been partially resolved in R2020b, R2020a, R2019b Update 5, and R2019a Update 8. Most Live scripts with loops now run as fast in the Live Editor as in the Editor or at the command line.
For example, with this change, the approximate execution times of the example from Lukas Müller's post above are:
R2018b: 200.2 s
R2020a: 0.160 s
The code was timed on a Windows 10 system with a 3.6 GHz Intel Xeon W-2133 CPU.
However, as mentioned in the replies below, the performance of rendering graphics within the Live Editor is still a known issue. Specifically, figures containing many graphics objects, such as those often created by basic graphics commands (plot, line, etc.) in tight loops, can be impacted.
For example, this code (based on the post by jdg below), takes 12 seconds to run in the R2020b Live Editor, and 4 seconds in the R2020b Command Window. The code was timed on a Windows 10 system with a 3.6 GHz Intel Xeon W-2133 CPU.
for i = 1:2700
plot(rand, rand, 'ob');
hold on;
end
drawnow
This issue is actively being worked on. As a workaround, code that creates figures with many graphics objects can often be rewritten to reduce the number of graphics objects being created. This change can improve the overall performance of the code. For example, vectorizing the graphics code or using a different graphics command such as “scatter” can reduce the run time of the code in the Live Editor to be almost equal to the run time in the Command Window.
Just as an example, when the code above is updated to gather the data first and only plot the data once, the code now takes 0.5 seconds to run in the R2020b Live Editor, and 0.45 seconds in the R2020b Command Window. The code was timed on a Windows 10 system with a 3.6 GHz Intel Xeon W-2133 CPU.
x = zeros(1, 2700);
y = zeros(1, 2700);
for i = 1:2700
x(i) = rand;
y(i) = rand;
end
scatter(x, y, [], 'ob');
drawnow
If you have any other questions, or other use cases that you would like us to better consider, please feel free to reach out to Technical Support to let us know.
  7 个评论
jdg
jdg 2020-7-10
Agree with Mike that things are not better. I am trying out Live Editor in R2020a on a MacBook Pro running macOS Catalina (v10.15.5). After experiencing very sluggish performance I came across this page.
One thing I noticed is that evaluating runtime in the .mlx file with tic/toc is misleading. The blue circle and pause button (both indicating the script is running) are present for much longer than the script is actually running. I had to time it manually to get an accurate estimate.
For example, the code below takes ~2 seconds in an m-file on my machine.
Running it in a .mlx file, I get tic/toc results of ~2.5 seconds. However the script is in executing mode (blue dot) for anywhere from 9 - 30 seconds.
Not looking for suggestions on how to improve the code itself. It's obviously very poorly structured.
@Philip Can you try this code on your machine? I am wondering if it's a Mac issue.
clc
tic
for A_gain = [0.5:0.1:1]
for A_phase = linspace(30,60,5)*pi/180
for B_gain = [0.5:0.1:1]
for B_phase = linspace(80,120,5)*pi/180
A = A_gain*(cos(A_gain) + j*sin(A_gain));
plot(real(A),imag(A),'b.');
B = B_gain*(cos(B_gain) + j*sin(B_gain));
plot(real(B),imag(B),'r.');
c = A+B;
plot(real(c), imag(c),'o');
hold on;
end
end
end
end
toc
Sukrit Ghorai
Sukrit Ghorai 2020-9-22
The lag is so much when we plot on live editor. I think my system is decent to run matlab smoothly but when it comes to live editor , any graphics on live editor such as plotting makes it lag so much. Also output inline mode is gets painful with plots (atleast my computer cant take it :( )

请先登录,再进行评论。

更多回答(7 个)

Gijs van Oort
Gijs van Oort 2017-5-31
The most annoying I think, is that editing is much slower too. After pressing a key, it takes noticeable time for the character to be shown on the screen. Also walking through the code with the arrow keys and scrolling are really slow. Due to this, I'm now ending up writing my code in a normal .m script and copying it to the .mlx when I'm happy with the results.
  2 个评论
Gijs van Oort
Gijs van Oort 2017-6-28
In the LiveScript, I was displaying some very long symbolic equations. I found out that this greatly reduced speed and responsiveness. It was useless anyway; 90% of the displayed equation would be typeset off the screen. After I disabled the displaying of the equations (adding a ; after the assignment), the thing became much faster (but still slower than I would wanted it to be)
Manoj
Manoj 2024-4-8
I agree with Gijs. Live editor is way slower even on really good spec machines even with R2023b

请先登录,再进行评论。


Prannay Jain
Prannay Jain 2016-11-15
Yes, the code runs slower in the live script than in the command line. Currently, there is no way to configure the amount of resource allocation for the live script.
I work for MathWorks and I have forwarded this feedback to the appropriate product team.
  7 个评论
Jan Kappen
Jan Kappen 2018-5-13
I have the feeling, being behind a corporate proxy makes things much worse. When I'm at home office without proxy the editor is much quicker. Do you experience the same?
Dom Dwyer
Dom Dwyer 2019-1-14
has this been fixed yet? we can't work with this product currently as it is too slow even on new computers

请先登录,再进行评论。


Tom Anderson
Tom Anderson 2017-1-9
编辑:Tom Anderson 2017-1-16
Please improve this! It's almost 50% slower to run .mlx versus .m...
I ran a code section for a live file using "Run Section" that took 72.971023 seconds. The same code .m file using "Run Section" took 52.701320 seconds. Repeated this test multiple times and .mlx is always a loser.
That's not very good. It's almost a 50% slowdown. It's not as though there's any extra interactivity between the code, either. Just waiting for the results both times, with the GUI locked up.
  1 个评论
Tom Anderson
Tom Anderson 2017-1-16
编辑:Tom Anderson 2017-1-16
Here's a great example I found to run much slower:
tic
for t = 1:1000000
if ~mod(t, 10000), disp(t), end
end
toc
The live code (.mlx): Elapsed time is 487.6064 seconds.
Hit F9 to run (or run as script): Elapsed time is 0.010989 seconds.
50,000 times slower? What gives?

请先登录,再进行评论。


Florian Blanchet
Florian Blanchet 2019-12-11
Hi,
Can you remove that feature or at least make it clear that is significantly slower and will reduce editor experience ?
How can you provide a feature that is so unusable without make it explicit it is still experimental ?

Ryan
Ryan 2017-3-25
I will definitely use this feature more when resource allocation improves.

Frieder Wittmann
Frieder Wittmann 2018-5-28
Has this been addressed in R2018a? Didn't see anything in the release notes.
  2 个评论
Will Perdikakis
Will Perdikakis 2018-8-28
Nope. Still brutally slow edits and execution.
Frieder Wittmann
Frieder Wittmann 2019-5-3
We're at 2019b now and despite all the advertisement for the future it is still unusable slow :-(

请先登录,再进行评论。


Juan José Trujillo
Hi,
I do not know what is the motivation for you to use the live scripts. I really find this a cool way of documenting and something which approaches a bit what you can do in Jupyter Notebooks.
In fact, I have been using successfully Jupyter Notebooks with the matlab engine in the last two years to run matlab code. I have worked that way since I have some python background and did not know live scripts until recently. Just lately I have got in touch with matlabs live scripts through a colleague and we have noticed latency which I do not experience through Jupyter Notebooks. I guess the mechanics here are really different and the Notebook approach almost resembles running bare scripts with a bit of overhead on the matlab engine.
Maybe you can give Jupyter Notebook a try and get better performance and with slightly better documentation capabilities with markdown.
  4 个评论
Juan José Trujillo
Hi Kouichi, sorry for answering that late. I am not really into it. But, As I understand the Matlab engine in Jupyter is just a thin wrapper which passess commands straight to a headless matlab instance. In fact any time a launch a matlab notebook I get fully new instance of Matlab working in the background. So I think you get the best of both worlds, or almost depending on the application. As Frieder says, still there are several applications that you do not have access to from the Jupyter Notebook.
A really cool application of this is for instance if you work on a remote headless system with long lived sessions. You just turn on and off your graphical interface (web browser) locally and connect to the server when you need it, but the Jupyter server and matlab instance stay alive on the remote side. I think you cannot do this kind of things with the matlab IDE, or correct me if I am wrong.
Kouichi C. Nakamura
Kouichi C. Nakamura 2018-12-18
Thank for the information about the backstage of Jupyter. Yeah, that makes sense!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Integration with Online Platforms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by