MATLAB Answers

MatLab runtime initialisation is slow

8 views (last 30 days)
2018b
We use MatLab as a libraty within our C# application.
We initialise the MatLab runtime and wait for it to finish
WS.mcr.EvaluateFunction(nameof (Initialise), numArgsOut, ref argsOut, argsIn);
This can take 10 to 120 secs. [no change to the library, the varioation can be seen on subsequent starts of the application].
Why does it take so long and why does it vary so much.
Nigel

  0 Comments

Sign in to comment.

Accepted Answer

Debarghya Kundu
Debarghya Kundu on 24 Nov 2020
In general MCR initialization takes around the same time (or faster) as starting MATLAB desktop, as it allocates resources and initializes its libraries. The process takes a bit of time due to its many libraries and its overall large size. Currently, there are no settings to reduce the initialization time of MCR.
When there are multiple MATLAB SDK compiler compiled component in one program (.NET assembly, JAVA package, Python package, c++ library), loading every component involves an MCR initialization step. The first MCR initialization will be the slowest, but the others should be much faster. This is because a lot of stuff is shared among all the MCR instances and will be set up by the first MCR instance, including all MATLAB runtime library loading, built-in data type initialization, MATLAB installed m-file tree parsing, java JVM startup and many others.
If the calls are consistently slow, check that its set up in a way where the execution is not cleaned up and recreated so that the MCR does not need to reinitialize. If the current MCR cache root is being cleared, specify a different cache location using the MCR_CACHE_ROOT environment variable. Set the MCR_CACHE_SIZE if the cache is being pruned.
Additionally, upgrading from an HDD to an SSD can improve MCR initialization, as disk usage is sometimes the performance bottleneck.

  0 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!