MATLAB Answers

App Designer updates much (20x) slower than GUIDE

164 views (last 30 days)
Bramvg
Bramvg on 5 Mar 2020
Commented: Peter on 29 Apr 2021
With App Designer I made an application that gets an image from a camera and after some processing displays it in a GUI. The problem is that it is extremely slow. It turns out this is due to the slow updating in the uifigure (using drawnow).
Below is a simple script to reproduce the problem. The script plots an image and a button, which calls a function that updates the image. The script does the same thing twice, once using uifigure (App Designer) and once using figure (GUIDE).
example_script.m:
close all hidden
clear
clc
%% app designer example
figure1 = uifigure('Name','UIFigure 1');
figure1.Position = [100 100 500 400];
axes1 = uiaxes(figure1);
axes1.Position = [50 50 400 300];
im1 = imagesc(axes1,rand([1280 1024]));
button1 = uibutton(figure1,'push');
button1.Position = [20 370 150 22];
button1.Text = 'push to refresh!';
button1.ButtonPushedFcn = {@buttonpushed,im1};
%% guide example
figure2 = figure(2);
figure2.MenuBar = 'none';
figure2.Position = [700 100 500 400];
axes2 = axes(figure2,'Units','pixels');
axes2.Position = [50 50 400 300];
im2 = imagesc(axes2,rand([1280 1024]));
button2 = uicontrol(figure2,'Style','pushbutton');
button2.Position = [20 370 150 22];
button2.String = 'push to refresh!';
button2.Callback = {@buttonpushed,im2};
%% callback function
function buttonpushed(~,~,h)
tic
im = rand([1280 1024]);
h.CData = im;
drawnow;
toc
end
The timing results from tic/toc in the callback function, for my computer and Matlab R2018b are:
  • For UIFigure 1: Elapsed time is 0.872563 seconds.
  • For Figure 2: Elapsed time is 0.042053 seconds.
(These timings are reproducible.) This is a factor 20 difference! And this means the difference between a snappy and an extremely sluggish GUI. The same performance difference is visible while loading the script.
Is this normal behavior or am I doing something wrong?

Answers (1)

Steven Lord
Steven Lord on 5 Mar 2020
Try calling
drawnow limitrate
instead of
drawnow
with no inputs.
  5 Comments
Peter
Peter on 29 Apr 2021
On Linux, this is even more ridiculous.
Using the script above, I get the following numbers, which are absolutely inacceptable.
Elapsed time is 0.106374 seconds. % guide
Elapsed time is 18.838314 seconds. % appdesigner, may vary from 4sec to minutes...
And sometimes it blocks even for minutes, blocking all other matlab windows either. I am running Matlab R2020b on Ubuntu 20.04 on a 16 core machine via a remote X-connection on a local network.
If I run it on the local graphic display, things look at first glance more promising:
Elapsed time is 0.02 seconds. % guide, when pressing the button more than once
Elapsed time is 0.05 seconds. % appdesigner, when pressing the button more than once
but the confusing thing is, that alternately pressing the buttons leads to quite unpredicatble update times ranging from 0.2 ... to several seconds.
On a more complex appdesigner Application I observed, that keyboard input in tables on Linux did not work although it worked on Win.

Sign in to comment.

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by