Skip to content

Halve the memory a tracking run kept in memory needs - #13

Merged
antonio-dimeglio merged 2 commits into
mainfrom
tracker-memory
Oct 29, 2026
Merged

antonio-dimeglio merged 2 commits into
mainfrom
tracker-memory

Conversation

@antonio-dimeglio

Copy link
Copy Markdown
Contributor

Summary

A tracking run with no output file kept each batch's streamlines as a tractogram of its own and joined them at the end, so for a moment it held every streamline twice, plus the per-batch copies. On a large run that pushes a 16 GB machine into swap, which slows the end of the run and whatever comes next, such as the viewer's Dissect workspace.

The kept points now go straight from each batch's buffer into one buffer that grows by a quarter when full, in place where the allocator allows it, and is trimmed at the end. Runs written to a file are unchanged. The result is the same tractogram, point for point, with the same end statuses.

Measurements

One million streamlines on the ISMRM example data (det, whole brain mask, seed 1), 431.6 million points (5.18 GB), on an Apple M-series laptop with 16 GB. Peak memory footprint from /usr/bin/time -l, which counts swapped and compressed memory; the same SHA-256 of the points and offsets in both runs.

Peak footprint Tracking Whole run
Before 11.0 GB 71 s 83 s
After 6.5 GB 62 s 64 s

The memory beyond the tractogram itself falls from 5.8 GB to 1.3 GB. A growth of 1.5 instead of 1.25 gave 7.4 GB at the same speed.

Tests

The existing test that compares a run kept in memory with the same run written to TCK and TRK, with batches of seven seeds, covers the buffer growing several times; the tracking, viewer and CLI tests pass.

@antonio-dimeglio
antonio-dimeglio merged commit d2b8b4a into main Oct 29, 2026
10 checks passed
@antonio-dimeglio
antonio-dimeglio deleted the tracker-memory branch October 29, 2026 22:00
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