Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions dimos/visualization/rerun/bridge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

from dataclasses import dataclass, field
from functools import lru_cache
import time
from typing import (
TYPE_CHECKING,
Any,
Expand Down Expand Up @@ -171,6 +172,7 @@ class Config(ModuleConfig):
# Static items logged once after start. Maps entity_path -> callable(rr) returning Archetype
static: dict[str, Callable[[Any], Archetype]] = field(default_factory=dict)

min_interval_sec: float = 0.1 # Rate-limit per entity path (default: 10 Hz max)
entity_prefix: str = "world"
topic_to_entity: Callable[[Any], str] | None = None
viewer_mode: ViewerMode = field(default_factory=_resolve_viewer_mode)
Expand Down Expand Up @@ -254,6 +256,16 @@ def _on_message(self, msg: Any, topic: Any) -> None:
# convert a potentially complex topic object into an str rerun entity path
entity_path: str = self._get_entity_path(topic)

# Rate-limit per entity path to prevent viewer memory exhaustion.
# High-bandwidth streams (e.g. 30fps camera) would otherwise flood
# the viewer with data faster than it can evict, causing OOM.
if self.config.min_interval_sec > 0:
now = time.monotonic()
last = self._last_log.get(entity_path, 0.0)
if now - last < self.config.min_interval_sec:
return
self._last_log[entity_path] = now
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp updated even when message is suppressed downstream

_last_log[entity_path] is written here — before _visual_override_for_entity_path is called. If the override converter returns None (i.e., the topic is suppressed), the slot is still "consumed" for this interval: the next arriving message for that entity path will be dropped by the rate limiter even though no frame was actually logged.

For purely suppressed topics this is harmless (nothing ever logs anyway), but for topics whose override sometimes returns None (e.g., conditional filtering), frames can be silently skipped at a lower effective rate than 1/min_interval_sec.

Consider moving the timestamp update to just before the rr.log calls, after confirming rerun_data is not None:

if self.config.min_interval_sec > 0:
    now = time.monotonic()
    last = self._last_log.get(entity_path, 0.0)
    if now - last < self.config.min_interval_sec:
        return
    # defer: update timestamp only after data is confirmed non-None


# apply visual overrides (including final_convert which handles .to_rerun())
rerun_data: RerunData | None = self._visual_override_for_entity_path(entity_path)(msg)

Expand All @@ -274,6 +286,7 @@ def start(self) -> None:

super().start()

self._last_log: dict[str, float] = {}
logger.info("Rerun bridge starting", viewer_mode=self.config.viewer_mode)

# Initialize and spawn Rerun viewer
Expand Down
Loading