Skip to content

Commit 44c8d26

Browse files
Read KIT data in cache-sized blocks
The reader asked for up to 100 MB per block, then cast the whole block to float64 and scaled it in place, so the working set was several hundred MB and none of it stayed in cache. raw.get_data(), interleaved cross-process medians: 136 MB file (161ch x 425000) 258.5 -> 145.6 ms 1.78x A sweep over 32/16/8/4/2/1 MiB puts the optimum at 2 MiB (32 MiB is only 1.14x, 8 MiB 1.38x, 4 MiB 1.66x, 1 MiB 1.60x). No shipped fixture regresses; two of them improve because they were already being split differently: ArtificalSignalData_Yokogawa_1khz.con 2.87 -> 2.26 ms 1.27x ArtificalSignalData_RICOH_1khz.con 3.06 -> 2.77 ms 1.10x Example_PQA160C_1001-export.con 0.99x 010409_Motor_task_coregist-export.con 0.98x Output is bit-identical on every readable KIT fixture. The large file was synthesised by tiling the raw-data section of data_berlin.con -- it is the last section in the file -- and patching n_samples in the acquisition header. Same treatment as #14241 and #14246; the constant differs because the optimum tracks time points per block, so it moves with the channel count.
1 parent 3e783e6 commit 44c8d26

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

mne/io/kit/kit.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ def __init__(self, sqd_version, *args, **kwargs):
8282
ValueError.__init__(self, *args, **kwargs)
8383

8484

85+
# read in cache-sized blocks rather than one huge one (1.8x on a 136 MB file);
86+
# each block is cast to float64 and scaled, so a smaller one stays in cache
87+
_BLOCK_BYTES = 2 * 1024**2
88+
89+
8590
@fill_doc
8691
class RawKIT(BaseRaw):
8792
r"""Raw object from KIT SQD file.
@@ -209,8 +214,7 @@ def _read_segment_file(self, data, idx, fi, start, stop, cals, mult):
209214

210215
n_bytes = sqd["dtype"].itemsize
211216
assert n_bytes in (2, 4)
212-
# Read up to 100 MB of data at a time.
213-
blk_size = min(data_left, (100000000 // n_bytes // nchan) * nchan)
217+
blk_size = min(data_left, (_BLOCK_BYTES // n_bytes // nchan) * nchan)
214218
with open(self.filenames[fi], "rb", buffering=0) as fid:
215219
# extract data
216220
pointer = start * nchan * n_bytes

0 commit comments

Comments
 (0)