jared-hughes / DesThree

Desmos bindings for three.js
3 stars 0 forks source link

Unnecessary rerenders #27

Closed jared-hughes closed 3 years ago

jared-hughes commented 3 years ago

This is a major performance issue. Something is wrong with dependency management, so many more renders are executed than necessary. Try changing the W variable in https://www.desmos.com/calculator/hhvvj3zyat — that should be fast, but the model is rerendered 75 (?) times instead of 1.

The cause is likely that rerender() is called every time each element of each list is changed.

A few remedy ideas:

  1. Throttle rerenders with requestAnimationFrame or a timer-based system akin to lodash's throttle function. This would be simple but has issues with ensuring the last update of a batch is always included
  2. Only rerender once after a shown list changes, instead of once per element. This should be done in addition to any other changes
  3. Limit rerenderings to once per graphChanged call. This would reduce the number of startup renders but have no effect on HelperExpression changes
  4. Limit rerenderings to once per HelperExpression value change. This would help if multiple arguments (in one function or spread across several) are linked to a single helper expression, but oftentimes (like in camera spherical coordinates), the Desmos variable affects several helper expressions.

I will likely not go with option 4 since it doesn't seem worth the effort. Option 1 might conceal the effects of improperly implementing the other options, so I'll implement it last.