Azzera filtri
Azzera filtri

R2022a slower than R2021a lagmatrix

2 visualizzazioni (ultimi 30 giorni)
Aaron Kaye
Aaron Kaye il 24 Mag 2022
Modificato: William Mueller il 28 Nov 2023
I updated from R2021a to R2022a, and my code is running much slower.
Here are benchmark times for one objective funciton evaluation.
  • R2021a Runtime: 30.9 seconds
  • R2022a Runtime: 87.9 seconds
Running the profiler it looks like lagmatrix is the most impacted command:
  • R2021a lagmatrix Runtime: 1.57 seconds (194703 calls)
  • R2022a lagmatrix Runtime: 68.22 seconds (194703 calls)
Have others had this issue? Am I missing some important package?
Other info: I'm using a MacBook Pro (16-inch, 2019), with a 2.4 GHz 8-Core Intel Core i9 processor, and 32 GB of memory.

Risposte (1)

William Mueller
William Mueller il 28 Nov 2023
Modificato: William Mueller il 28 Nov 2023
Hi Aaron,
You're correct that there were significant changes to LAGMATRIX in the R2022a release. In fact, the function was substantially rewritten. Part of this was to bring old code up to current standards and patterns used elsewhere in the toolbox for things like input parsing and error checking. More substantially, the function was updated to accommodate new input data types, like tables and timetables, and new features, like the ability to specify pre-sample and post-sample data, and the shape of the output. These changes are documented in the Release Notes section of the LAGMATRIX reference page.
That said, you probably aren't interested in any of these new features, at least in the application you describe. If you were relying on R2021a functionality, you were inputting a numerical matrix and returning a numerical matrix. In the new version of LAGMATRIX, much of the new code for handling tabular data will be bypassed in that scenario. However, some of the new, and different, error checking is added to the code path in any input scenario, and while the difference in execution time is insignificant in any single call to LAGMATRIX (our most typical user scenario), it adds up over the 194703 calls you describe.
You indicate that you're evaluating an objective function in some sort of optimization. It's typical for solvers to evaluate the objective function many times in a single iteration, and if the optimization is slow to converge the number of calls to the objective can reach the levels you describe. For this reason, objective functions should be as lean as possible. Assembling toolbox functions, though they're optimized for their intended purpose, may result in the unsatisfactory slow-downs you're experiencing. Fortunately, our toolbox functions are all open-source ("toolbox" suggests building your own applications), so the core code for lagging a matrix is available to you without all of the parsing, error-checking, and other features that are irrelevant to your use case. In these circumstances, our suggestion is always to use only the core code necessary (lagging a time series is pretty simple). If you do this, you'll see a performance improvement over even the R2021a release, and one that will not be affected by any future updates to the toolbox.

Categorie

Scopri di più su Data Type Identification in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by