Skip to content

Fix/python memoryleak replay#2002

Closed
bogwi wants to merge 6 commits intodimensionalOS:devfrom
bogwi:fix/python-memoryleak-replay
Closed

Fix/python memoryleak replay#2002
bogwi wants to merge 6 commits intodimensionalOS:devfrom
bogwi:fix/python-memoryleak-replay

Conversation

@bogwi
Copy link
Copy Markdown
Collaborator

@bogwi bogwi commented May 7, 2026

Problem

Running dimos --dtop --replay run unitree-go2 causes one of the Python processes to grow in memory. Even if the dimos-viewer was closed midway the replay that would not change anything and the memory would still grow.

The problem was discussed by @leshy and @aclauer .

Previously, the code was doing this:

delay = target_time - current_time
If delay is negative, emit the frame immediately to catch up.
This meant that if the playback fell behind by 0.5 seconds, it would try to emit 500 milliseconds worth of video, lidar, and odometry frames instantly to catch up.

Solution

Re-Anchoring on Delay: Added a death spiral breaker logic. If the stream detects that it has fallen behind by more than 0.2 seconds (200 milliseconds), instead of trying to catch up with an instantaneous stream of frames, it re-anchors the time to the current frame (start_local_time = time.time()).

Precise Blocking Sleep: Replaced the manual chunked time.sleep() loop with threading.Event().wait(delay). This provides single-call sleep mechanism that has practically zero drift, completely preventing the systematic time accumulation over long playbacks, while still allowing instant cancellation if you stop the replay.

…ngs on mac; refactor timed_playback for improved threading and emission handling; use MultipleAssignmentDisposable
@bogwi bogwi closed this May 7, 2026
@bogwi bogwi reopened this May 7, 2026
@bogwi bogwi changed the base branch from main to dev May 7, 2026 06:13
Comment thread dimos/mapping/voxels.py Outdated
Comment thread dimos/utils/testing/replay.py Outdated
@bogwi bogwi marked this pull request as draft May 7, 2026 06:32
@bogwi bogwi marked this pull request as ready for review May 7, 2026 06:48
…) and MultipleAssignmentDisposable(); make it run on a threading.Thread we start explicitly.
Comment thread dimos/utils/testing/replay.py Outdated
Comment thread dimos/utils/testing/replay.py
@dimensionalOS dimensionalOS deleted a comment from greptile-apps Bot May 8, 2026
@dimensionalOS dimensionalOS deleted a comment from codecov Bot May 8, 2026
@leshy
Copy link
Copy Markdown
Contributor

leshy commented May 8, 2026

hm this bugs me a bit, two things:

  1. why would loading messages ever be so slow? we are just decoding sqlite blobs here.
  2. why would slow loading of messages ever cause a memory leak? it should only cause us to be too slow, it's a single loop, we are never able to schedule more then one message emission

are we sure it isn't something simpler, like we are not garbage collecting messages after passing them down to subscribers?

@leshy
Copy link
Copy Markdown
Contributor

leshy commented May 8, 2026

yeah, issue was garbage collection
#2025

@leshy leshy closed this May 8, 2026
@bogwi bogwi deleted the fix/python-memoryleak-replay branch May 8, 2026 15:42
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