Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Compiled Matlab GUI code starts up too slow...

Subject: Compiled Matlab GUI code starts up too slow...

From: scho

Date: 14 Oct, 2010 02:36:04

Message: 1 of 27

I made a GUI program, and trying Matlab compiler to make it a standalone program.
I am happy that I was able to make an excutable file, and have it running on a
different machine which does not have Matlab installed.
Of course, I had to install MCR there once, and it can help to run the executable.

But my complaint is that the GUI window shows up too slow, and when I check
the task manager, the memory usage keeps increasing slowly, and once it gets to
certain point it stops increasing and showing the GUI window that I made.

Obviously, I think it takes too much time, but I wonder the some preparation
step to launch the GUI window usually takes such a bit of time.

Any comments would be appreciated.

--

Subject: Compiled Matlab GUI code starts up too slow...

From: ImageAnalyst

Date: 14 Oct, 2010 02:53:55

Message: 2 of 27

How much time does it take? Mine take on the order of 30 seconds or
so (less time than to launch an MS Office app).

Subject: Compiled Matlab GUI code starts up too slow...

From: scho

Date: 16 Oct, 2010 12:44:03

Message: 3 of 27

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a4838119-7e1f-4864-85a3-4f1cbcfac721@n26g2000yqh.googlegroups.com>...
> How much time does it take? Mine take on the order of 30 seconds or
> so (less time than to launch an MS Office app).

Isn't 30 secs a lot, and enough time for users being curious if the program is really running or not ? I often had to open the task manager to see what's going on. Maybe, I am too impatient.

And, I am wondering, if there is anyway for me to open up an image window real quick when I execute the program, and later on my main GUI window comes up, much like executing Matlab ?

--

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 19 Aug, 2011 17:28:08

Message: 4 of 27

>
> Isn't 30 secs a lot, and enough time for users being curious if the program is really running or not ? I often had to open the task manager to see what's going on. Maybe, I am too impatient.
>
> And, I am wondering, if there is anyway for me to open up an image window real quick when I execute the program, and later on my main GUI window comes up, much like executing Matlab ?
>



I was wondering the same things!

I have put a trace at the beginning of my executable gui. After clicking the exe, it takes 30 seconds to appear. And the worst part is that nothing shows up during this process. Is there any way to decrease this time? I would also like to make a splash screen which appears as soon as executing the program if possible. Any suggestions?

Subject: Compiled Matlab GUI code starts up too slow...

From: Bruno Luong

Date: 19 Aug, 2011 17:53:08

Message: 5 of 27

"Arda " <ardaaksu@hotmail.com> wrote in message <j2m6f8$1ig$1@newscl01ah.mathworks.com>...
> >
> > Isn't 30 secs a lot, and enough time for users being curious if the program is really running or not ? I often had to open the task manager to see what's going on. Maybe, I am too impatient.
> >
> > And, I am wondering, if there is anyway for me to open up an image window real quick when I execute the program, and later on my main GUI window comes up, much like executing Matlab ?
> >
>
>
>
> I was wondering the same things!
>
> I have put a trace at the beginning of my executable gui. After clicking the exe, it takes 30 seconds to appear. And the worst part is that nothing shows up during this process. Is there any way to decrease this time? I would also like to make a splash screen which appears as soon as executing the program if possible. Any suggestions?

Beside the very first time where the program is lauched: most of my compiled applications take:

1) Console Black windows appears < 100 ms
2) Some message starts to appears on ~ +1 sec
3) A main gui window appears ~+1 sec

I could show another textbox between 2) and 3), but why bother for 1sec?

The time I observe is no where close to 30 seconds.

Bruno

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 19 Aug, 2011 19:01:11

Message: 6 of 27

> Beside the very first time where the program is lauched: most of my compiled applications take:
>
> 1) Console Black windows appears < 100 ms
> 2) Some message starts to appears on ~ +1 sec
> 3) A main gui window appears ~+1 sec
>
> I could show another textbox between 2) and 3), but why bother for 1sec?
>
> The time I observe is no where close to 30 seconds.
>


What about that first time? After you restarted your computer, if you execute the program before even opening the matlab, how long does it take the message to appear?

Subject: Compiled Matlab GUI code starts up too slow...

From: Bruno Luong

Date: 19 Aug, 2011 19:35:12

Message: 7 of 27

"Arda " <ardaaksu@hotmail.com> wrote in message <j2mbtn$jv2$1@newscl01ah.mathworks.com>...
>
>
> What about that first time? After you restarted your computer, if you execute the program before even opening the matlab, how long does it take the message to appear?

Less than 3 seconds.

Opening Matlab has nothing to do with execution, since the application supposes to work on the computer without Matlab. But "the first time"I meant the very first time a newly compiled program is launched, where it needs to unpacked the files and store it somewhere. All successive runs takes 3 seconds - regardless whereas the computer is just restarted or not and Matlab is opened or not.

Bruno

Subject: Compiled Matlab GUI code starts up too slow...

From: ImageAnalyst

Date: 19 Aug, 2011 20:22:06

Message: 8 of 27

I agree with Bruno. The very first time may take around 30 seconds
because it has to unpack a bunch of stuff to that weird hidden
folder. But once you've done that once, subsequent times just take a
few seconds. You can put fprintf(1, 'Now doing this.....'); in your
startup code if you want to show the various things your code is doing
in the black console window while it's initializing and before your
main GUI is shown, or even after. For example in myGUI_OpenFcn() you
might have

fprintf(1, 'Now opening mat file (%s) to initialize variables...\n',
fullMatFileName);

So put a bunch of stuff in there to keep the user entertained while it
launches.

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 19 Aug, 2011 23:02:09

Message: 9 of 27

> Less than 3 seconds.
>
> Opening Matlab has nothing to do with execution, since the application supposes to work on the computer without Matlab. But "the first time"I meant the very first time a newly compiled program is launched, where it needs to unpacked the files and store it somewhere. All successive runs takes 3 seconds - regardless whereas the computer is just restarted or not and Matlab is opened or not.
>

It cant be, shouldnt be! Even the following simplest gui takes 20 seconds to display 'started' when executed for the first time after a restart. Once it starts, speed is pretty much the same for rest (with the case running through Matlab). But if I try again before restarting the computer it takes only 1 or 2 seconds to display 'started'. Unlike yours however, when i restart the computer and try again, i have to wait 20 seconds again! And i must say, my processor is i7..

By the way, i am creating the exe file with deploytool (in 2011a) with default settings..


tic,disp('started')
model=javax.swing.table.DefaultTableModel(num2cell(reshape(magic(10),[],2)),{'a','b'});
table=javax.swing.JTable(model);
sorter=javax.swing.table.TableRowSorter(model);
table.setRowSorter(sorter);
pane=javax.swing.JScrollPane(table);
frame=javax.swing.JFrame('');
frame.add(pane,java.awt.BorderLayout.CENTER);
frame.setSize(300,250);
frame.setVisible(true);
toc,disp('ended')

Subject: Compiled Matlab GUI code starts up too slow...

From: Bruno Luong

Date: 19 Aug, 2011 23:26:09

Message: 10 of 27

You might try to compile with -C option and
http://www.mathworks.com/help/toolbox/compiler/brl4_f1-1.html

and define MCR_CACHE_ROOT environment variable so that the ctf file does extract the *_mcr at the folder where it is freed from automatically cleaning every time the computer reboots.

Bruno

Subject: Compiled Matlab GUI code starts up too slow...

From: ImageAnalyst

Date: 20 Aug, 2011 02:13:12

Message: 11 of 27

Just to clarify, I believe the MCR_CACHE_ROOT is defined on the
compiling computer and does not need to be defined on the target
computer. Perhaps if you do that it will unpack stuff to that
constant folder every time instead of some different temporary folders
in the \Documents and settings/user/whateverCrazyTemporaryFolder. I
actually set my environment variable to dot for other reasons and so
haven't fully investigated if the unpacked stuff goes to different
folders on every run. I do know that if you compile a *new* version
though, it will go into a different folder because it has new and
different stuff to unpack. If you set MCR_CACHE_ROOT = . then at
least these folders will be subfolders of the folder where your exe
lives rather than some weird hidden folder under Documents and
Settings. I've probably totally confused Arda :-( I'm sorry that
they make it so confusing but that's the way it is.

Subject: Compiled Matlab GUI code starts up too slow...

From: Yair Altman

Date: 20 Aug, 2011 18:31:08

Message: 12 of 27

"Arda " <ardaaksu@hotmail.com> wrote in message <j2mq1h$5is$1@newscl01ah.mathworks.com>...
> > Less than 3 seconds.
> >
> > Opening Matlab has nothing to do with execution, since the application supposes to work on the computer without Matlab. But "the first time"I meant the very first time a newly compiled program is launched, where it needs to unpacked the files and store it somewhere. All successive runs takes 3 seconds - regardless whereas the computer is just restarted or not and Matlab is opened or not.
> >
>
> It cant be, shouldnt be! Even the following simplest gui takes 20 seconds to display 'started' when executed for the first time after a restart. Once it starts, speed is pretty much the same for rest (with the case running through Matlab). But if I try again before restarting the computer it takes only 1 or 2 seconds to display 'started'. Unlike yours however, when i restart the computer and try again, i have to wait 20 seconds again! And i must say, my processor is i7..


This is a known issue with Matlab-compiled applications. In R2011b this problem is supposed to be reduced. But the core issue of having to unpack and load the MCR the first time it is used after a computer restart remains painful. In some cases I observed start-up times of up to a minute (obviously this depends on the specific hardware and CPU load).

The work-around that I have successfully used is to create a small wrapper application that simply displays a static "Please wait... Loading XYZ..." splash image (with a generic configuration of the image, size, etc.), then launches the main (compiled) application, and finally deletes the splash image when it detects that the main application has actually started. This gives the user an immediate feedback that the application is loading and this seems to resolve the issue. Anyone wishing to have this wrapper application, please contact me offline (altmany at gmail dot com).

Yair Altman
http://UndocumentedMatlab.com

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 20 Aug, 2011 19:56:08

Message: 13 of 27

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2mreh$9cn$1@newscl01ah.mathworks.com>...
> You might try to compile with -C option and
> http://www.mathworks.com/help/toolbox/compiler/brl4_f1-1.html
>
> and define MCR_CACHE_ROOT environment variable so that the ctf file does extract the *_mcr at the folder where it is freed from automatically cleaning every time the computer reboots.
>
> Bruno

Bruno, thank you! It sounds like that might be the problem. I have no clue about what i should do but i will study on it. I actually hope to get a result..

One more thing that i forgot to mention; the code i gave above creates a java frame and when i compile it, it doesnt work like a figure window. After appearing on screen it suddenly disappears and my application terminates (i also checked from task manager). I know that using a Matlab figure instead of a java frame is a solution but is it possible to use a java frame with a reasonable way? (using a pause shouldnt be one for example..)

Subject: Compiled Matlab GUI code starts up too slow...

From: ImageAnalyst

Date: 20 Aug, 2011 20:26:03

Message: 14 of 27

On Aug 20, 3:56 pm, "Arda " <ardaa...@hotmail.com> wrote:
> One more thing that i forgot to mention; the code i gave above creates a java frame and when i compile it, it doesnt work like a figure window. After appearing on screen it suddenly disappears and my application terminates (i also checked from task manager). I know that using a Matlab figure instead of a java frame is a solution but is it possible to use a java frame with a reasonable way? (using a pause shouldnt be one for example..)

---------------------------------------------------------------------
How are you launching it? Are you double-clicking on the icon in
Windows Explorer (My Computer)? Yes if it bombs it will barf a bunch
of stuff to the console window and then immediately close down the
console window. You need to run it from the command line or MATLAB in
order to have all the stuff it barfed up remain for you to inspect.
Here, try this:

Take these lines and save them to a file and call the file
RunDOSPromptHere.reg:

REGEDIT4

[HKEY_CLASSES_ROOT\Directory\Shell\DosPrompt]
@="Run MS-DOS Prompt here"
[HKEY_CLASSES_ROOT\Directory\Shell\DosPrompt\Command]
@="Cmd /k CD \"%L\" "

Now double click that file and say yes when it asks you for permission
to change the registry. What this will do is give you a new context
menu when you right click on a folder in Windows Explorer. You can
browse to any folder (such as the one where your exe lives) and then
right click and select "Run MS-DOC Prompt here" from the pop-up
context menu. It will immediately give you a console window with that
folder as the current directory. Basically it's the same as doing
Start/Run/cmd and then typing cd "c:\whatever\blahblahblah\yadayada"
Now, once you're in that folder, type the name of your executable and
it will run. BUT when it barfs and exits, all the stuff you printed
out plus all the error messages will remain in the console window for
you to inspect. You can do this on your target computer.

Have you verified that the executable works on your development
machine? You can do that by cd'ing to the folder where you told it to
put the exe. Then, in the MATLAB command window type ! (exclamation
mark) followed immediately (no space) with the name of your
executable. If it crashes also on your computer then that gives you
something to track down easier than deploying and trying to debug on
the target computer. The crash info will appear, and remain, in the
MATLAB command window.

Finally since you paid $5000 for the compiler, the Mathworks is pretty
helpful in helping you. I've had them track down some pretty esoteric
issues with compiled programs before. So if the entries in the FAQ
have all been tried and all failed, give the Mathworks tech support a
try - might as well get some support for your $5k.
Good luck,
ImageAnalyst

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 20 Aug, 2011 22:13:08

Message: 15 of 27

@ImageAnalyst, I believe you completely misunderstand me. My executable program does not crush, it works as it supposed to be. It creates some java objects (in which there is also a frame) and when it completes the job terminates itself. Whereas if there is a figure in the program it waits user to close the window.. The main task here is to ensure that program waits the user to terminate it when compiled without a figure!

Subject: Compiled Matlab GUI code starts up too slow...

From: Bruno Luong

Date: 20 Aug, 2011 23:03:08

Message: 16 of 27

"Arda " <ardaaksu@hotmail.com> wrote in message <j2pbhk$jvd$1@newscl01ah.mathworks.com>...
> The main task here is to ensure that program waits the user to terminate it when compiled without a figure!

Can you use waitfor in one of the java objects? Such as

waitfor(frame, 'Visible','off')

Bruno

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 20 Aug, 2011 23:33:07

Message: 17 of 27

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2pefb$rrm$1@newscl01ah.mathworks.com>...
> "Arda " <ardaaksu@hotmail.com> wrote in message <j2pbhk$jvd$1@newscl01ah.mathworks.com>...
> > The main task here is to ensure that program waits the user to terminate it when compiled without a figure!
>
> Can you use waitfor in one of the java objects? Such as
>
> waitfor(frame, 'Visible','off')
>
> Bruno

I didnt even try the waitfor because i had assumed that it needed a valid matlab handle something like javacompenent gives. It turns out that java components are also used with waitfor. But i am not sure exactly what 'waitfor' actually waits for; because when i close the java frame it still waits :)
Then i tried something else, i changed the closing callback as follows;
frame.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
Guess what, when i close the frame now it also closes Matlab :) But surprisingly it worked for standalone. Program is terminated only when i close the window. I think using with 'isdeployed' might be a solution..

Subject: Compiled Matlab GUI code starts up too slow...

From: Arda

Date: 24 Aug, 2011 14:31:28

Message: 18 of 27

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2mreh$9cn$1@newscl01ah.mathworks.com>...
> You might try to compile with -C option and
> http://www.mathworks.com/help/toolbox/compiler/brl4_f1-1.html
>
> and define MCR_CACHE_ROOT environment variable so that the ctf file does extract the *_mcr at the folder where it is freed from automatically cleaning every time the computer reboots.
>
> Bruno

@Bruno, nothing changed unfortunately.
I have compiled my application with -C option and ctf files were extracted at the same folder with my executable file. However it still waits a very long time when the first time executed after restarting the computer. Everything is same with the case that ctf is embedded in exe file except some weird files in ctf folder. What is wrong here?

Subject: Compiled Matlab GUI code starts up too slow...

From: Bruno Luong

Date: 24 Aug, 2011 14:45:28

Message: 19 of 27

"Arda " <ardaaksu@hotmail.com> wrote in message
>
> @Bruno, nothing changed unfortunately.
> I have compiled my application with -C option and ctf files were extracted at the same folder with my executable file. However it still waits a very long time when the first time executed after restarting the computer. Everything is same with the case that ctf is embedded in exe file except some weird files in ctf folder. What is wrong here?

I don't know, it might be many reasons: your exe load some DLL, some anti-virus kicks in, etc. Contact TMW customer support if you think it's abnormal and the issue is not related to how your computer is setup.

Bruno

Subject: Compiled Matlab GUI code starts up too slow...

From: Robin Jens

Date: 25 Aug, 2011 11:11:10

Message: 20 of 27

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j332q8$9je$1@newscl01ah.mathworks.com>...
> "Arda " <ardaaksu@hotmail.com> wrote in message
> >
> > @Bruno, nothing changed unfortunately.
> > I have compiled my application with -C option and ctf files were extracted at the same folder with my executable file. However it still waits a very long time when the first time executed after restarting the computer. Everything is same with the case that ctf is embedded in exe file except some weird files in ctf folder. What is wrong here?
>
> I don't know, it might be many reasons: your exe load some DLL, some anti-virus kicks in, etc. Contact TMW customer support if you think it's abnormal and the issue is not related to how your computer is setup.
>
> Bruno

Hi Yair

I am very interested to get a copy of your small wrapper application. I have a large GUI that takes some time to start up especially first time when the MCR also need to be started. Therefore it could be very nice to get a copy of your small wrapper application that when I click the exe file it first run the small wrapper application and next the matlab code. When it then open the GUI window it exit the small wrapper application.

Best Regards

Robin

Subject: Compiled Matlab GUI code starts up too slow...

From: Krishan

Date: 21 Feb, 2012 23:45:12

Message: 21 of 27

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <87213120-3739-4596-8bda-a1d575e5895f@g8g2000prn.googlegroups.com>...
> I agree with Bruno. The very first time may take around 30 seconds
> because it has to unpack a bunch of stuff to that weird hidden
> folder. But once you've done that once, subsequent times just take a
> few seconds. You can put fprintf(1, 'Now doing this.....'); in your
> startup code if you want to show the various things your code is doing
> in the black console window while it's initializing and before your
> main GUI is shown, or even after. For example in myGUI_OpenFcn() you
> might have
>
> fprintf(1, 'Now opening mat file (%s) to initialize variables...\n',
> fullMatFileName);
>
> So put a bunch of stuff in there to keep the user entertained while it
> launches.

----

This only seems to work when i compile a Console Application as oppose to a Standalone Windows Application.

After the GUI is finally launched the console window remains visible when it would be preferable for it to be hidden. Moreover, when the console window is closed, the GUI also exits.

Is there a way around this?

Thanks.

Subject: Compiled Matlab GUI code starts up too slow...

From: amit pathania

Date: 22 May, 2012 15:36:06

Message: 22 of 27

"scho" wrote in message <i95qak$c1d$1@fred.mathworks.com>...
> I made a GUI program, and trying Matlab compiler to make it a standalone program.
> I am happy that I was able to make an excutable file, and have it running on a
> different machine which does not have Matlab installed.
> Of course, I had to install MCR there once, and it can help to run the executable.
>
> But my complaint is that the GUI window shows up too slow, and when I check
> the task manager, the memory usage keeps increasing slowly, and once it gets to
> certain point it stops increasing and showing the GUI window that I made.
>
> Obviously, I think it takes too much time, but I wonder the some preparation
> step to launch the GUI window usually takes such a bit of time.
>
> Any comments would be appreciated.
>
> --

I too experienced this problem.How u overcome it?Can you add splash screen to .exe file?

Subject: Compiled Matlab GUI code starts up too slow...

From: Yair Altman

Date: 22 May, 2012 17:13:06

Message: 23 of 27

"amit pathania" <sujanian.amit@gmail.com> wrote in message <jpgbp6$567$1@newscl01ah.mathworks.com>...
> "scho" wrote in message <i95qak$c1d$1@fred.mathworks.com>...
> > I made a GUI program, and trying Matlab compiler to make it a standalone program.
> > I am happy that I was able to make an excutable file, and have it running on a
> > different machine which does not have Matlab installed.
> > Of course, I had to install MCR there once, and it can help to run the executable.
> >
> > But my complaint is that the GUI window shows up too slow, and when I check
> > the task manager, the memory usage keeps increasing slowly, and once it gets to
> > certain point it stops increasing and showing the GUI window that I made.
> >
> > Obviously, I think it takes too much time, but I wonder the some preparation
> > step to launch the GUI window usually takes such a bit of time.
> >
> > Any comments would be appreciated.
> >
> > --
>
> I too experienced this problem.How u overcome it?Can you add splash screen to .exe file?

As I noted above, this is a known issue with Matlab-compiled applications. In some cases I observed start-up times of up to a minute (obviously this depends on the specific hardware and CPU load).

The work-around that I have successfully used is to create a small wrapper application that simply displays a static "Please wait... Loading XYZ..." splash screen and logo (with a generic configuration of the logo image, size, etc.), then launches the main (compiled) application, and finally deletes the splash image when it detects that the main application has actually started. This gives the user an immediate feedback that the application is loading and this seems to resolve the issue. Anyone wishing to have this wrapper application, please contact me offline (altmany at gmail dot com).

Yair Altman
http://UndocumentedMatlab.com

Subject: Compiled Matlab GUI code starts up too slow...

From: Yair Altman

Date: 26 Jul, 2012 19:23:13

Message: 24 of 27

For anyone interested, here is the post explaining my splash wrapper utility for compiled (deployed) Matlab applications:
http://UndocumentedMatlab.com/blog/splash-window-for-deployed-applications

Yair Altman
http://UndocumentedMatlab.com
 

Subject: Compiled Matlab GUI code starts up too slow...

From: Marc

Date: 13 Nov, 2012 21:44:15

Message: 25 of 27

If all you want is at least a prompt with a message you can use the -R option when compiling your file at least the end user would know that something is happening.

mcc -m hello.m -R '-startmsg,"Message_Without_Space"'

you can find more info in Matlab help about this

Subject: Compiled Matlab GUI code starts up too slow...

From: elbaz samuel

Date: 19 Sep, 2013 19:40:08

Message: 26 of 27

"Marc " <marc.genest@nrc-cnrc.gc.ca> wrote in message <k7uevf$p2e$1@newscl01ah.mathworks.com>...
> If all you want is at least a prompt with a message you can use the -R option when compiling your file at least the end user would know that something is happening.
>
> mcc -m hello.m -R '-startmsg,"Message_Without_Space"'
>
> you can find more info in Matlab help about this


Marc,

Are you sure your command is working because i try it. And it doesn't work ...

Subject: Compiled Matlab GUI code starts up too slow...

From: Peter

Date: 13 Aug, 2014 13:08:07

Message: 27 of 27

If you are using deploytool to compile your code, under Project - Settings-Toolboxes on path uncheck any toolboxes that aren't needed by your executable. I recently had this issue and the above steps cut the executable file size in half and significantly reduced the start time of the executable.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us