Repository navigation
performance of mesh_import can be improved #1474
Description
in compas the parsing of meshes is performed in compas python code, rather than via a dependency.
trimesh would be a solid contender since its easy to install and yields numpy arrays.
loading meshes could be about twice as fast (frankly, I expected an even greater contrast), but 2x is not to be sneezed at.
there are 2 possible routes:
- make
trimesha hard dependency - make
trimesha soft dependency - factor out the existing mesh loading implementation and replace by
trimeshcalls
I strongly suggest making trimesh a hard dependency (updating requirements.txt) since once a dependency it is complimentary to compas.datastructures.Mesh. The soft route is using trimesh when found (as an alternative code path)
when going for the hard dependency I suggest refactoring mercilessly and factoring out the older implementations.
from line_profiler import profile
def test_mesh_read_performance_old():
@profile
def test_import():
for i in range(10):
msh: Mesh = Mesh.from_ply(compas.get_bunny())
print(f"faces parsed {len(msh.facedata)}")
del msh
test_import()
def test_mesh_read_performance_trimesh():
import trimesh
@profile
def test_import():
for i in range(10):
msh = trimesh.load(compas.get_bunny())
print(f"faces parsed {len(msh.faces)}")
del msh
test_import()
def test_mesh_read_performance_meshio():
import meshio
@profile
def test_import():
for i in range(10):
msh = meshio.read(compas.get_bunny())
print(f"faces parsed {msh.cells_dict['triangle'].shape[0]}")
del msh
test_import()
test_robot_library.py::test_mesh_read_performance_old
============================== 1 passed in 4.17s ===============================
PASSED [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451
test_robot_library.py::test_mesh_read_performance_trimesh
============================== 1 passed in 2.23s ===============================
PASSED [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451
test_robot_library.py::test_mesh_read_performance_meshio
============================== 1 passed in 2.37s ===============================
PASSED [100%]faces parsed 69451
faces parsed 69451
faces parsed 69451
Activity
tomvanmele commentedon Jul 2, 2025
hi @jf---
we can only start doing this in COMPAS 3, because of backward compatibility with older versions of Rhino.
development of C3 has stalled a bit, but i will restart it by opening a discussion and related development project where we can collect suggestion for the new API and new features...
jf--- commentedon Jul 2, 2025
@tomvanmele sounds like a plan (I'd love chip in wrt C3, I have some
compas_fabspecific ideas I'd love to run by you and @gonzalocasas ). Wrt triage, what about tagging issues that should surface when C3 is due?