Skip to content

Read #subsystem#/MCOS property values on demand - #256

Open
Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:lazy-subsystem
Open

Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:lazy-subsystem

Conversation

@Thenewmanator15

Copy link
Copy Markdown

matopen reads the whole #subsystem#/MCOS cell (class FileWrapper__), which holds the property values of every object in the file, before any variable is asked for. A read usually needs only the objects its variables reach, and acquisition code often saves many unreferenced snapshots, so this reads the cell on demand:

  • LazyCell, an AbstractArray{Any} over the cell's references, reads an element (and keeps it) the first time it is indexed;
  • load_subsys! keeps views into it (@view mcos_data[3:(end - 1), 1], …) rather than copies, which would read everything;
  • files opened for writing ("r+") still read it in full, since saving objects appends to prop_vals_saved;
  • prop_vals_saved becomes AbstractVector{Any} to hold the view; v7 (MAT_v5) files, whose subsystem is one decompressed blob, are unchanged.

On a 1.6 GB acquisition file (7,940 MATLAB objects: 2,058 timetables, 5,770 datetimes, 30 of the acquisition class), reading its one variable now touches 718 of 11,764 property values, and a digest of everything matread returns is identical to master's. New test: after matopen nothing in the cell has been read, and reading one variable of user_defined_classdefs.mat reads only part of it; "r+" still reads it all. Full suite passes (586).

To be plain about the benefit: on those files I measured no speed difference, warm or cold (matopen 0.62 s on master vs 0.64 s with this, first touch of an unread file) — their property values are small, and a cold open is dominated by reading /#refs# metadata off disk, whichever step does it first. It should matter for files whose unreferenced objects hold large property values, but I have no such file to show, so please close it if you'd rather not take it without that. Related: #247 (partial reading).

🤖 Generated with Claude Code

The MCOS cell (class FileWrapper__) holds the property values of every object in the
file, and matopen read all of them. A read usually needs only the objects its
variables reach, and acquisition code often saves many unreferenced snapshots, so a
LazyCell now reads an element the first time it is indexed, and load_subsys! keeps
views into it rather than copies. Opens for writing ("r+") still read it in full,
since saving objects appends to it.

On a 1.6 GB acquisition file (7,940 objects), reading its one variable touches 718 of
11,764 values, with identical results. New test: nothing is read at matopen, and
reading one variable reads only part of the cell.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant