Skip to content

Conversation

@flferretti
Copy link
Collaborator

@flferretti flferretti commented May 15, 2025

This PR enhances the codebase by fixing typos, refactoring classes, and optimizing Gazebo SDF processing with caching and batch support. Moreover, it updates the build system to use hatchling and improves the command-line interface.

First loading run:

# %timeit -n1 -r1 rod.Sdf.load(model_path)
< 678 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)
> 592 ms ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each)

Successive loading run:

# %timeit rod.Sdf.load(model_path)
< 657 ms ± 39.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
> 12.1 ms ± 396 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

Switching model frame convention to URDF:

# %timeit sdf.model.switch_frame_convention(frame_convention=rod.FrameConvention.Urdf)
< 196 ms ± 4.98 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
> 168 ms ± 9.18 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)

Exporting to URDF:

# %timeit UrdfExporter(pretty=True, gazebo_preserve_fixed_joints=True).to_urdf_string(sdf=sdf)
< 237 ms ± 2.44 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
> 206 ms ± 9.41 ms per loop (mean ± std. dev. of 7 runs, 10 loops each)
Test Script

import icub_models
import rod
from rod.urdf.exporter import UrdfExporter

model_path = icub_models.get_model_file("iCubGazeboV2_5")

# First loading run
%timeit -n1 -r1 _ = rod.Sdf.load(model_path)

# Successive loading run
%timeit _ = rod.Sdf.load(model_path)

sdf = rod.Sdf.load(model_path)

# Switching model frame convention to URDF
%timeit sdf.model.switch_frame_convention(frame_convention=rod.FrameConvention.Urdf)

# Exporting to URDF
%timeit _ = UrdfExporter(pretty=True, gazebo_preserve_fixed_joints=True).to_urdf_string(sdf=sdf)

@flferretti flferretti self-assigned this May 15, 2025
@flferretti flferretti force-pushed the refactor_repo branch 2 times, most recently from 1729d04 to e9dae82 Compare May 15, 2025 17:10
@flferretti flferretti force-pushed the refactor_repo branch 3 times, most recently from 09c4db3 to 9a50870 Compare September 29, 2025 09:28
@flferretti flferretti changed the title Refactor codebase to improve maintainability and usability Refactor codebase to improve performance, maintainability and usability Sep 29, 2025
- Add LRU cache for repeated SDF content processing to avoid redundant subprocess calls
- Optimize temporary file handling by writing directly to /tmp on Unix systems
- Add environment isolation (IGN_PARTITION/GZ_PARTITION) to prevent interference
- Implement batch processing support for multiple descriptions
- Add cache management with clear_cache() method
- Improve string parsing with early exit for SDF tag detection
- Use optimized subprocess bufsize for better I/O performance
@flferretti flferretti requested a review from xela-95 September 29, 2025 10:59
@flferretti flferretti marked this pull request as ready for review September 29, 2025 10:59
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