R2022a slower than R2021a lagmatrix

8 ビュー (過去 30 日間)
Aaron Kaye
Aaron Kaye 2022 年 5 月 24 日
編集済み: William Mueller 2023 年 11 月 28 日
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.

回答 (2 件)

Sanju
Sanju 2023 年 11 月 20 日
If your MATLAB code is running slower after updating from MATLAB R2021a to MATLAB R2022a, and “lagmatrix “ is significantly affected, consider the below steps:
  1. Check MATLAB R2022a release notes for changes related to “lagmatrix”.
  2. Review and optimize your code, exploring more efficient alternatives or configurations.
  3. Consider parallel computing for potential speed-up.
  4. Ensure third-party packages (that are required) are compatible and up to date.
  5. Check and configure hardware acceleration settings.
  6. Use MATLAB's profiler to identify bottlenecks beyond “lagmatrix”.
The above are some general steps to follow.
You can also refer to the MATLAB R2022a release notes if required,
Hope this Helps!
Thanks.

William Mueller
William Mueller 2023 年 11 月 28 日
編集済み: William Mueller 2023 年 11 月 28 日
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.

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by