any tips for making the library run faster?
Hi, Thanks for this awesome library! I'm getting great results but the computation time is very long... Any tips on how to make it run faster? I'm running on windows, c++ like this:
coacd::Params params; params.preprocess_mode = "on"; params.prep_resolution = 150; params.pca = false; params.mcts_max_depth = 2; params.mcts_iteration = 60; params.merge = true; params.threshold = 0.02; coacd::Model convexMesh; convexMesh.Load(vertices, indices); convexParts = coacd::Compute(convexMesh, params);
for my mesh, with these parameters t took a few minutes! I tried making the threshold bigger and the prep_resolution smaller. and that helps but the computation is still very long, and the results are not as good... any further options for multithreading? for GPU?
thanks! Inbal
Hi, the code supports using OpenMP for parallel computing, have you already enabled that?
I was able to make the library quite a bit faster (at least 3X) by performing some simple optimizations. The main changes, IIRC, were:
- Passing large objects by const reference, especially vectors.
- Removing the use of std::pow() for computing small integral powers.
- Reducing heap allocations by caching containers.
- Using faster hash maps.
Also, since the library allocates quite a lot of memory, it may be worth using a different memory allocator if building with multithreading. I found Mimalloc to give good results.
I was able to make the library quite a bit faster (at least 3X) by performing some simple optimizations. The main changes, IIRC, were:
- Passing large objects by const reference, especially vectors.
- Removing the use of std::pow() for computing small integral powers.
- Reducing heap allocations by caching containers.
- Using faster hash maps.
Also, since the library allocates quite a lot of memory, it may be worth using a different memory allocator if building with multithreading. I found Mimalloc to give good results.
Hi, Can you share your repo?
I’ve been experimenting with CoACD and wanted to share some insights on tuning parameters for better performance based on my tests:
- threshold: This drives the trade-off between detail and speed. Lower values (e.g., 0.01) produce more detailed decompositions but take much longer. I found 0.05 or higher speeds things up noticeably, though you’ll trade off some precision.
- mcts_nodes: Affects how smooth the decomposition is. Low values (e.g., 10) are faster but can fragment results; I settled on 20 as a good balance for decent quality without much slowdown.
- mcts_iterations: This tweaks detail with minimal runtime impact. I used 1000 without seeing major delays—seems efficient enough up to that range.
- mcts_max_depth: Major performance lever! Keeping it at 1 is fast and works for simpler meshes, but going to 2 or higher (like your 2) slows things down a lot due to deeper searches. Try 1 if speed’s the goal.
- merge: Enabling this tanks performance because of the extra merging step. I skipped it (
false) for my case and got faster results—only use it if you need combined parts.
coacd_mesh = coacd.Mesh(mesh.vertices, mesh.faces)
parts = coacd.run_coacd(
coacd_mesh,
threshold=0.05,
mcts_nodes=20,
mcts_iterations=1000,
mcts_max_depth=1,
merge=False,
)