Skip to content

Fix ~2x peak memory in _read_into_data_array by clearing Future._result#477

Merged
aldenks merged 3 commits intomainfrom
claude/debug-memory-usage-spike-g0Rgi
Mar 1, 2026
Merged

Fix ~2x peak memory in _read_into_data_array by clearing Future._result#477
aldenks merged 3 commits intomainfrom
claude/debug-memory-usage-spike-g0Rgi

Conversation

@aldenks
Copy link
Member

@aldenks aldenks commented Mar 1, 2026

concurrent.futures.as_completed holds an internal set of all futures for
the duration of iteration. Each Future retains its _result (the numpy
array from read_data) even after .result() is called. Since the sum of
all read results equals the shared buffer size, this doubles peak memory.

Clear future._result immediately after copying data into the shared
memory buffer. Verified this reduces peak from ~X to ~0.1X above
baseline (where X = shared buffer size).

https://claude.ai/code/session_01AzdTz8SLnEW4jSUPV2prJ9

claude added 3 commits March 1, 2026 14:30
concurrent.futures.as_completed holds an internal set of all futures for
the duration of iteration. Each Future retains its _result (the numpy
array from read_data) even after .result() is called. Since the sum of
all read results equals the shared buffer size, this doubles peak memory.

Clear future._result immediately after copying data into the shared
memory buffer. Verified this reduces peak from ~X to ~0.1X above
baseline (where X = shared buffer size).

https://claude.ai/code/session_01AzdTz8SLnEW4jSUPV2prJ9
@aldenks aldenks merged commit e170d68 into main Mar 1, 2026
5 checks passed
@aldenks aldenks deleted the claude/debug-memory-usage-spike-g0Rgi branch March 1, 2026 15:03
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.

2 participants