MATLAB: Simulink slower to compile when ‘SrcWorkspace’ set to ‘current’ (call to sim a function)

simulinksource workspace

I received a rather heavy model (.slx ~57Mo, 40k parameters and signals) from a client, and I need to run it several times for test purposes. To run the model, I call a function (e.g. runTest()) that load every parameters and signals and then call sim function. Here is the problem :
When the sim function is called with option SrcWorkspace set to current (i.e. runTest() workspace), the model is stuck at step "Compiling : Evaluating block parameter." for a very long time (hours scale)
However, when I assign all variables in base workspace and I call sim with SrcWorkspace set to base, this step take a reasonable amount of time (minutes scale).
Do you have any idea why calling sim within function workspace slow down the compilation step ?

Best Answer

Do you have an apple-to-apple fair comparison? Might it be that when you specify 'SrcWorkspace' as 'current' in runTest(), the data is also loaded in base workspace thus reduces the availability of memory?
Put a breakpoint in runTest() and run "memory" in Command Window to compare.
The default SrcWorkspace for a Simulink model is base, speifying function workspace might slow down a little bit but should not be that significant.
The Simulink model itself is always loaded into the memory used by MATLAB, even though you run load_system() inside runTest().
Another alternative is to use Simulink Data Dictionary or Simulink Model Workspace to store the data.