compas-dev / compas-dev/compas
performance of `mesh_import` can be improved
- Dominant language
- Python
- Stars
- 386
- Forks
- 122
- Avg merge
- 11d 46m
- Merged PRs (30d)
- 1
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:
1. make `trimesh` a hard dependency
2. make `trimesh` a soft dependency
3. factor out the existing mesh loading implementation and replace by `trimesh` calls
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
Contributor guide
Research direction
Start with requirements.txt and the existing Mesh.from_ply path used by test_mesh_read_performance_old in test_robot_library.py. Compare the proposed trimesh and meshio approaches against the existing benchmark using compas.get_bunny(). Done means selecting and implementing a dependency strategy, preserving the reported face count, and demonstrating the intended performance improvement.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, python
- Domain
- performance
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100