Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve model handling speed #31

Merged
merged 11 commits into from
May 17, 2024
Merged

Conversation

flferretti
Copy link
Contributor

@flferretti flferretti commented Apr 18, 2024

This pull request includes several code improvements and bug fixes. Here is a summary of the changes:

  • Use structural pattern matching (NOTE: This requires Python>=3.10, so I can eventually drop this)
  • Use utf-8 encoding when reading from files (Avoids file read error in Windows)
  • Cache tree transforms
  • Cache gazebo executable path
  • General exceptions improvements
  • General typing improvements

Benchmarks:

%timeit _ = rod.Sdf.load(sdf=urdf_path, is_urdf=True)
< 683 ms ± 24.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
> 434 ms ± 11.9 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit sdf.model.switch_frame_convention(frame_convention=rod.FrameConvention.Urdf)
< 511 ms ± 8.95 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
> 44 ms ± 178 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)
%timeit _ = UrdfExporter.sdf_to_urdf_string(
    sdf=sdf, pretty=True, gazebo_preserve_fixed_joints=True
)
< 549 ms ± 5.71 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
> 73.1 ms ± 432 µs per loop (mean ± std. dev. of 7 runs, 10 loops each)

C.C. @diegoferigo

@flferretti flferretti marked this pull request as ready for review April 26, 2024 08:40
@diegoferigo
Copy link
Member

@flferretti there are many conflicts after #34 and #35. Do you want to port the changes over the future main? Otherwise I can take care of it since I was the one that introduced all the conflicts.

@flferretti
Copy link
Contributor Author

@flferretti there are many conflicts after #34 and #35. Do you want to port the changes over the future main? Otherwise I can take care of it since I was the one that introduced all the conflicts.

I can handle that, thank you!

@flferretti flferretti force-pushed the flferretti-patch-1 branch 2 times, most recently from b3d595e to 8d6da11 Compare May 17, 2024 12:59
@flferretti
Copy link
Contributor Author

Ready for review @diegoferigo, I also fixed a minor typo here

elif frame.attached in {model.name, "__model__"}:

Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

Looks almost good, I have only a doubt on a possible change of behavior.

src/rod/utils/gazebo.py Show resolved Hide resolved
@flferretti flferretti force-pushed the flferretti-patch-1 branch 2 times, most recently from 833f1f9 to bdaf332 Compare May 17, 2024 14:48
flferretti and others added 2 commits May 17, 2024 16:58
Copy link
Member

@diegoferigo diegoferigo left a comment

Choose a reason for hiding this comment

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

Beyond the suggestion below that somehow got lost, this PR looks good thanks! We can finalize the type hints migration with list, dict, set, |None, etc in the future.

src/rod/utils/frame_convention.py Outdated Show resolved Hide resolved
@diegoferigo diegoferigo merged commit 1964e85 into ami-iit:main May 17, 2024
16 checks passed
@flferretti flferretti deleted the flferretti-patch-1 branch May 20, 2024 07:08
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