Profile and debug load function
Show older comments
I have a .mat file containing an object of a custom Matlab class that mainly consists of a big data table of type table, stored in one of the class' properties. The table contains ~20k rows and contains datetime, double, categorical arrays, and objects of class idnlarx, i.e. estimated nonlinear nlarx models.
The mat file is 520 MB in size (mat file v7 with enabled compression, v7.3 makes the size 10x) and takes between 240 and 290 seconds to load.
I'm trying to speed up the loading process which is clearly CPU bound. I think the problem is the idnlarx model which utilizes most of the space (> 1 GB when loaded to RAM and instantiated).
And I'd like to understand what takes so much time to load, but the profiler only shows this:

...

That means, 94% are self-time of the load function.
How do I find out what takes so long?
Thanks,
Jan
Answers (1)
You could pursue your hypothesis by extracting the table from an object, then saving the idnlarx column to its own .mat file. Then, you could check how much time it takes to load back in. I suspect your hypothesis is correct, however, because I routinely load .mat files that are ~500 MB and, while it takes some time, it is nowhere near a minute long, let alone 4 minutes.
8 Comments
Jan Kappen
on 18 Feb 2024
Moved: Matt J
on 18 Feb 2024
The speed difference is likely because data storage in the "array class" form is much more memory-contiguous. Maybe you could write a saveobj method that converts the array-of-scalars to a scalar-of-arrays, just for the purpose of .mat file storage. Similarly, youw ould write a loadobj method that will transform it back. That way, you wouldn't have to refactor the rest of your class clode.
Jan Kappen
on 26 Feb 2024
Walter Roberson
on 26 Feb 2024
load() is a built-in function. Timing analysis only goes as far as the built-in function, without being able to show timings of the C or C++ code.
Matt J
on 26 Feb 2024
but that's no solution for the built-in idnlarx class which utilizes most of the memory :(
Not sure why that's a problem. As we've been discussing, the amount of memory is probably not the issue. It's the data organization. Is it that you cannot form an array of idnlarx objects? If so, maybe the saveobj method can store just the idnlarx constructor argument data that built it. How long would it take to rebuild the idnlarx objects from the initial constructor data?
Jan Kappen
on 26 Feb 2024
According to your original post, the idnlarx objects are members of your custom class. It is that class whose saveobj/loadobj method I am suggesting you customize, not the internal loadobj method of idnlarx. Transform the idnlarx members into something simpler and more compact, something which can be used to rebuild the original idnlarx memebrs later.
Jan Kappen
on 27 Feb 2024
Categories
Find more on Nonlinear ARX Models in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!