Skip to content

Conversation

@Mayankm96
Copy link
Contributor

Description

This MR passes the stage attribute to the functions where applicable. This helps avoid unnecessary get_current_stage() calls as that calls the USD context and can be at times expensive. It is a better practice to give the stage as much as possible.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions bot added documentation Improvements or additions to documentation enhancement New feature or request isaac-lab Related to Isaac Lab team labels Jan 3, 2026
@Mayankm96 Mayankm96 closed this Jan 3, 2026
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 3, 2026

Greptile Summary

This PR implements a performance optimization by passing the stage parameter explicitly throughout the codebase to avoid expensive get_current_stage() calls from the USD context.

Key Changes:

  • Introduced new XformPrimView class in isaaclab.sim.views as a replacement for Isaac Sim's XFormPrim, with native stage parameter support
  • Updated SimulationContext to pass stage to downstream operations
  • Modified all spawner functions (shapes.py, meshes.py, from_files.py) to accept and propagate stage parameter
  • Updated sensors (Camera, TiledCamera, RayCaster) to use XformPrimView with explicit stage parameter
  • Refactored InteractiveScene to pass stage to all asset initialization calls
  • Added comprehensive test suite (test_views_xform_prim.py) and benchmark script to validate the changes
  • Simplified clear_stage() predicate logic for better readability

The changes follow a consistent pattern: functions that previously called get_current_stage() internally now accept an optional stage parameter (defaulting to None, which triggers the call only when needed). This allows callers to pass a cached stage reference, eliminating redundant USD context lookups.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes are well-structured performance optimizations that maintain backward compatibility (all stage parameters default to None), include comprehensive tests, and follow consistent patterns throughout. The new XformPrimView class is thoroughly tested with 1156 lines of test coverage.
  • No files require special attention

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sim/views/xform_prim_view.py New XformPrimView class introduced with stage parameter support for efficient batched transform operations
source/isaaclab/isaaclab/sim/simulation_context.py Major refactoring to pass stage to avoid repeated get_current_stage() calls; singleton pattern implementation
source/isaaclab/isaaclab/scene/interactive_scene.py Replaced XFormPrim with XformPrimView and passes stage parameter to avoid redundant calls
source/isaaclab/isaaclab/sensors/camera/camera.py Updated to use XformPrimView with stage parameter instead of XFormPrim
source/isaaclab/isaaclab/sim/spawners/shapes/shapes.py All schema and material binding functions now receive stage parameter
source/isaaclab/isaaclab/sim/spawners/meshes/meshes.py All schema and material binding functions now receive stage parameter
source/isaaclab/test/sim/test_views_xform_prim.py Comprehensive test suite for new XformPrimView class covering initialization, getters, and setters

Sequence Diagram

sequenceDiagram
    participant User as User Code
    participant Scene as InteractiveScene
    participant Camera as Camera Sensor
    participant XformView as XformPrimView
    participant Spawner as Spawner Functions
    participant USD as USD Context
    participant Stage as USD Stage

    Note over User,Stage: Before: Multiple get_current_stage() calls

    User->>Scene: Initialize scene
    Scene->>USD: get_current_stage()
    USD-->>Scene: stage
    Scene->>Camera: Initialize camera
    Camera->>USD: get_current_stage()
    USD-->>Camera: stage
    Camera->>XformView: XFormPrim(path)
    XformView->>USD: get_current_stage()
    USD-->>XformView: stage

    Note over User,Stage: After: Stage passed explicitly

    User->>Scene: Initialize scene
    Scene->>USD: get_current_stage() (once)
    USD-->>Scene: stage
    Scene->>Camera: Initialize camera (stage=stage)
    Camera->>XformView: XformPrimView(path, stage=stage)
    Note over XformView: Uses passed stage directly
    Scene->>Spawner: spawn_shape(cfg, stage=stage)
    Spawner->>Stage: bind_material(prim, material, stage=stage)
    Note over Spawner,Stage: All operations use cached stage

    Note over User,Stage: Performance Benefit: Eliminates redundant USD context calls
Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant