Repository navigation
Speed up load_xdf and fix reading truncated sample chunks - #180
Merged
Merged
Conversation
Read numeric samples chunks at once instead of sample by sample, falling back to the per-sample reader if the chunk length does not match the samples. Only format per-chunk debug messages when they are logged, replace lstsq in the jitter removal with a closed-form line fit, and simplify the ADMM iteration in _robust_fit. Also drop a chunk that is cut off at the end of the file instead of returning a last sample with leftover values from the previous sample, and remove the unused pyxdf.pxd. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Ping @sappelhoff - Gemini was not wrong! Could you review and test these changes, because you said another agent did not review it favorably? |
Contributor
|
Thanks for picking this up, I am glad there was something salvageable. Will dig out the review and will have another look at it (personally and with another Gemini agent) |
Contributor
Author
|
Thanks! It would be helpful if you tried loading some of your real-world XDF files to see if nothing broke. |
Contributor
|
This was the critical agent feedback and how you addressed it:
Generally I think this PR is great and it does its job. Tested on a lot (nearly 100) of real life recordings I have here. Some numbers:
|
sappelhoff
approved these changes
Oct 23, 2026
Contributor
Author
|
Very nice, thanks for testing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

This picks up the proposals from #179 (after a critical review) plus a few things the issue missed. It differs in three ways:
.pxdinstead of editing it.Measured speedups were 2.5–5x (claimed: 2.7–7x), almost all from chunk parsing. Time series are identical; time stamps differ by up to about 1e-11 s when clock sync and dejittering are on.
Changes
f.tell()for every chunk)._jitter_removalinstead oflstsq(~6.7x faster, no large temporary arrays)._robust_fit(mathematically equivalent, ~2.5x faster, but only ~10 ms per stream).readintosilently returned a short read).pyxdf.pxd, which was never part of the build and no longer matched the code.Performance
Synthetic recordings (64 channels, float32, 500 Hz, 30 min, 32-sample chunks; last row 8 channels, 1000 Hz, 10 min, 2-sample chunks),
load_xdfwith default settings:mainTime series are byte-identical to
main. Time stamps are identical without clock synchronization and dejittering; with them, they differ by at most ~1e-11 s because the fits are computed in a different order.Tests
New
test/test_read_chunk.pycovers all numeric formats with all time stamp patterns, wrong chunk lengths (first and last chunk), truncated files, empty chunks, flag/length mismatches, and checks_robust_fitagainst the original implementation.