Skip to content

Read the file only once when select_streams is a list of dicts - #181

Merged
cbrnr merged 2 commits into
xdf-modules:mainfrom
cbrnr:single-pass-select-streams
Oct 28, 2026
Merged

cbrnr merged 2 commits into
xdf-modules:mainfrom
cbrnr:single-pass-select-streams

Conversation

@cbrnr

@cbrnr cbrnr commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Fixes #60.

When select_streams was a list of dicts, load_xdf first read the whole file with resolve_streams() to find the matching stream IDs, then read it again to load them. Now each StreamHeader is checked against the criteria while loading, and chunks from streams that don't match are skipped. Matching still uses match_streaminfos on the same stream-info dicts, now built by a shared _streaminfo() helper, so selection behaves as before. The "No matching streams found" error is now raised after reading the file instead of before. On a 478 MB test file, loading only a small selected stream became about twice as fast, because there is no longer a separate pass over the file.

The new tests cover int, list-of-int and dict selections, and the no-match and invalid-input errors. They check that the file is opened only once and that the selected streams match a full load.

cbrnr added 2 commits October 27, 2026 21:43
Match each stream header against the select_streams criteria while loading
instead of resolving all streams in a separate pass over the file first.
Fixes xdf-modules#60.
@cbrnr
cbrnr requested a review from cboulay October 27, 2026 20:50

@cboulay cboulay left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't be able to test directly but I looked at the modest code changes and everything looks correct to me. We should see significant load time improvement on large files with many streams.

@cbrnr
cbrnr merged commit 0abff88 into xdf-modules:main Oct 28, 2026
6 checks passed
@cbrnr
cbrnr deleted the single-pass-select-streams branch October 28, 2026 08:22
@cbrnr

cbrnr commented Oct 28, 2026

Copy link
Copy Markdown
Contributor Author

I think it depends on whether this will result in significant performance gains (file size, size of the loaded streams, compressed or not, file on network), but it's a conceptual improvement for sure.

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.

Using select_streams argument traverses file twice

2 participants