Skip to content

performance of mesh_import can be improved #1474

Open

Description

@jf---

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

Activity

  1. tomvanmele commented on Jul 2, 2025

    @tomvanmele
    Member

    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...

  2. jf--- commented on Jul 2, 2025

    @jf---
    ContributorAuthor

    @tomvanmele sounds like a plan (I'd love chip in wrt C3, I have some compas_fab specific ideas I'd love to run by you and @gonzalocasas ). Wrt triage, what about tagging issues that should surface when C3 is due?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions