JuliaRobotics / MeshCatMechanisms.jl

3D Visualization of mechanisms and URDFs using MeshCat.jl and RigidBodyDynamics.jl
Other
40 stars 9 forks source link

Creating a MechanismVisualizer now takes over a minute? #23

Closed tkoolen closed 5 years ago

tkoolen commented 5 years ago
using RigidBodyDynamics
urdf = joinpath(dirname(pathof(RigidBodyDynamics)), "..", "test", "urdf", "Acrobot.urdf")
mechanism = parse_urdf(urdf)

using MeshCat, MeshCatMechanisms
@time mvis = MechanismVisualizer(mechanism, URDFVisuals(urdf))

results in 70.614526 seconds (143.61 M allocations: 7.937 GiB, 5.79% gc time). Something is very wrong.

julia> versioninfo()
Julia Version 1.0.1
Commit 0d713926f8 (2018-09-29 19:05 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin14.5.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)

Toml files.

rdeits commented 5 years ago

I've been noticing this too. I was curious if MeshCat itself was to blame, as I have a few parameterized types that could easily just have abstract fields, but making that change had no noticeable effect on the compilation time of MeshCat.

I think the first thing to do would be to try to separate loading the geometries from actually spawning the visualizer. I would be very interested in the relative timings of the three lines here: https://github.com/JuliaRobotics/MeshCatMechanisms.jl/blob/0295e987aa7da4fedf55fd8a0903a25ae2692a29/src/visualizer.jl#L17-L21

Would you be willing to try those three lines separately and see which one is the worst offender?

tkoolen commented 5 years ago

Almost all time is spent in

https://github.com/JuliaRobotics/MeshCatMechanisms.jl/blob/0295e987aa7da4fedf55fd8a0903a25ae2692a29/src/visualizer.jl#L18

Not sure about the root cause yet.

tkoolen commented 5 years ago

Commenting out these lines:

https://github.com/JuliaRobotics/MechanismGeometries.jl/blob/3196e71ee1c6752d06d3a21100f8de543db7f1d1/src/urdf.jl#L174-L176

makes the visual_elements compilation time reasonable again. In particular, it seems to be the parse_link! call.

tkoolen commented 5 years ago

Might be the nested map do?

tkoolen commented 5 years ago

Much better now, but do you have any other ideas for what could be causing the remaining compilation latency?

I briefly tried using SnoopCompile to generate precompile statements for MeshCatMechanisms by the way, but that didn't help. I'm thinking it's probably due to compilation of third party code (meaning we'd have to add precompile statements to those other packages).

tkoolen commented 5 years ago

Anyway, it doesn't take anywhere close to a minute anymore, so I'll close this.