yuki-koyama / elasty

A research-oriented elastic body simulator
MIT License
363 stars 29 forks source link

Improve performances of the bending constraint #42

Open jspdown opened 3 years ago

jspdown commented 3 years ago

While running some experiments with bending constraints I noticed some missed optimizations due to calc_grad_of_normalized_cross_prod_wrt_*:

https://github.com/yuki-koyama/elasty/blob/67c7a15c1483fe1979b8b3af64be4f34e110c760/src/constraint.cpp#L110-L119

Since the cross product of p1, p2, and p1, p3 are already computed earlier for the n_0 and n_1, this value could be reused for computing partial_n_*_per_partial_p_*.

This won't drastically improve the performances but I noticed while profiling that cross product represents 11% of the time spent in my simulation. Like for https://github.com/yuki-koyama/elasty/issues/14, it improves performances but impacts code readability.