Skip to content

Count /#refs# only when the file is opened for writing - #257

Open
Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:readonly-refs
Open

Thenewmanator15 wants to merge 1 commit into
JuliaIO:masterfrom
Thenewmanator15:readonly-refs

Conversation

@Thenewmanator15

Copy link
Copy Markdown

matopen counts the entries of /#refs# (fid.refcounter = length(g) - 1) so that a write can name the references it adds. A read-only open never writes, so this counts only when the file is opened for writing. MATLAB puts every cell element and object value in /#refs#: an acquisition file of 1.6 GB here has 100,007 entries, and counting them on the first touch of the file took 1.3 s (the group's index is walked from disk).

Tests. A read-only open leaves the count alone and an "r+" open still takes it. A cell and a struct with a cell field are appended, in one "r+" session and then a second, to three kinds of file: one written by MAT.jl (numbered references, where a name reused because the count was skipped would collide), one written by MATLAB (cell.mat, lettered references), and one with no /#refs# (simple.mat). In each, the variables already there read back unchanged and the appended ones read back as a plain matwrite + matread gives them. There was no "r+" test before; skipping the count for "r+" as well fails all three cases. Full suite passes (593).

To be plain about the benefit: on the one unread file of that kind I could still test, a cold matopen with this change was no faster (4.05 s, against 3.4 s for a byte-identical copy on master): the first read of /#refs# metadata costs the same whichever step makes it, and on warm files the difference is within noise. So this removes work a read-only open never needs rather than delivering a measured speed-up; please close it if that isn't worth a change here.

🤖 Generated with Claude Code

matopen counted the entries of /#refs# to number the references a write adds. A
read-only open never writes, and /#refs# holds every cell element and object value in
the file: 100,007 entries in a 1.6 GB acquisition file, where counting them took 1.3 s
of a 2.6 s first open (the group's index is walked from disk). Opens for writing still
count, so appended references keep unique names.

Tests: a read-only open leaves the count alone and an "r+" open takes it; cells and a
struct with a cell field appended, in one session and in a second, to a file written
by MAT.jl (numbered references, where a reused name would collide), one written by
MATLAB, and one with no /#refs#: existing variables stay intact and the appended ones
read back as a plain write and read gives them. Skipping the count for "r+" as well
fails all three.

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