Skip to content

fix lcm load speed#975

Merged
leshy merged 1 commit intodevfrom
loadspeed
Jan 12, 2026
Merged

fix lcm load speed#975
leshy merged 1 commit intodevfrom
loadspeed

Conversation

@leshy
Copy link
Contributor

@leshy leshy commented Jan 10, 2026

just made some loading lazy, needs repo wide consideration tho

@leshy leshy requested a review from a team January 10, 2026 07:01
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 10, 2026

Greptile Overview

Greptile Summary

This PR optimizes LCM module load time by implementing lazy imports and refactoring module dependencies.

Key Changes

1. Lazy Import Optimization

  • Moved rerun import in CameraInfo.py from module-level to inside to_rerun() method
  • Moved matplotlib.pyplot and rerun imports in PointCloud2.py to be lazy-loaded within their respective functions
  • These changes defer heavy library imports until actually needed, significantly improving module load speed

2. Module Refactoring

  • Relocated JpegSharedMemoryEncoderMixin class from lcmpubsub.py to jpeg_shm.py
  • This removes turbojpeg, Image, and ImageFormat dependencies from the core LCM module
  • The class implementation remains identical - purely a code organization change
  • Import chain verified: lcmpubsub.py no longer imports jpeg_shm.py, breaking the dependency

3. Dead Code Removal

  • Removed unused logger setup from spec.py

Impact Assessment

No breaking changes: The moved class was not in the __all__ exports and no external code imports it from lcmpubsub
Backward compatible: All public APIs remain unchanged
Performance improvement: Heavy imports (rerun, matplotlib, turbojpeg) now load on-demand
Code organization: Better separation of concerns with JPEG shared memory functionality in its own module

Confidence Score: 5/5

  • This PR is safe to merge with no risk
  • All changes are refactoring/optimization without logic modifications. The moved class is byte-for-byte identical, imports are correctly lazy-loaded, no breaking changes detected, and the refactoring achieves the stated goal of improving LCM load speed.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
dimos/msgs/sensor_msgs/CameraInfo.py 5/5 Moved rerun import to lazy load in to_rerun() method - improves module load time without affecting functionality
dimos/msgs/sensor_msgs/PointCloud2.py 5/5 Moved matplotlib and rerun imports to lazy load - improves module load time, correctly placed in functions that use them
dimos/protocol/pubsub/jpeg_shm.py 5/5 Moved JpegSharedMemoryEncoderMixin class from lcmpubsub.py - implementation identical, all imports present
dimos/protocol/pubsub/lcmpubsub.py 5/5 Removed JpegSharedMemoryEncoderMixin class and heavy imports (turbojpeg, Image) - improves LCM load speed
dimos/protocol/pubsub/spec.py 5/5 Removed unused logger import and setup - clean up of dead code

Sequence Diagram

sequenceDiagram
    participant App as Application Code
    participant LCM as lcmpubsub.py
    participant JPEG as jpeg_shm.py
    participant Camera as CameraInfo.py
    participant PC2 as PointCloud2.py
    
    Note over LCM,JPEG: Before: lcmpubsub imports turbojpeg at module load
    Note over LCM,JPEG: After: jpeg_shm owns turbojpeg, isolated from lcmpubsub
    
    App->>LCM: import LCM
    activate LCM
    Note over LCM: ✅ No longer loads turbojpeg<br/>✅ Faster module load
    LCM-->>App: Ready (fast)
    deactivate LCM
    
    App->>JPEG: import JpegSharedMemory
    activate JPEG
    Note over JPEG: Loads turbojpeg, Image<br/>Only when needed
    JPEG-->>App: Ready
    deactivate JPEG
    
    App->>Camera: import CameraInfo
    activate Camera
    Note over Camera: ✅ Rerun NOT loaded yet
    Camera-->>App: Ready (fast)
    deactivate Camera
    
    App->>Camera: camera.to_rerun()
    activate Camera
    Note over Camera: Lazy load rerun here
    Camera-->>App: Rerun archetype
    deactivate Camera
    
    App->>PC2: import PointCloud2
    activate PC2
    Note over PC2: ✅ Matplotlib & Rerun NOT loaded
    PC2-->>App: Ready (fast)
    deactivate PC2
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@spomichter
Copy link
Contributor

Curious how much this speeds up loading

@leshy
Copy link
Contributor Author

leshy commented Jan 12, 2026

Curious how much this speeds up loading

from 6 seconds to 0.1ms :D

@leshy leshy merged commit ced2782 into dev Jan 12, 2026
13 checks passed
@spomichter spomichter deleted the loadspeed branch January 12, 2026 19:04
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.

3 participants