Saving and loading matrices with vpa entries with save and load commands is extremely slow
4 views (last 30 days)
Show older comments
I am generating matrices consisting of vpa entries. They are not extremely large (1000 by 500), and when stored, the file takes only 60 MB. However, the save command takes HOURS to save them, and the load command HOURS to load them back. Is there any way to speed up the process? I have try lots of configurations without success: -v6, -v7, -v7.3, -nocompression, etc. Any piece of advice would be highly appreciated.
0 Comments
Answers (1)
Walter Roberson
on 26 May 2020
You are correct, this can happen. The slowdown is inside the symbolic engine, when it is asked to convert into a character representation that can be saved. The process ends up expanding all internally shared sub-expressions, and converts each identifier into a unique identifier (you cannot just use the name of the identifier because identifiers have scope in the symbolic toolbox. X - X is not necessarily 0 because they might be referring to X generated by two different functions.)
Disk speed is not the limitation here: the problem is the in-memory processing to describe (for writing) or build (upon reading) the symbolic data structures.
My experience is that this is a distinct weakness in the symbolic toolbox. I have complained about the performance to Mathworks in the past.
In my situations, I was always looking for human readable representation so I never tested further than that, but if my memory of documentation is correct, it is possible to use direct symbolic engine commands to save an expression in binary, and this is not the same as a mat file. If what I have in mind works, it would save to a binary file inside the symbolic engine, using a format specific to that engine, and you would instruct the symbolic engine to read the file directly. This would not be compatible with load() /save() and would not in itself create links between your workspace and symbolic variables that live in the symbolic engine, but you can work around those. I do not know what the performance would be at the moment.
3 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!