Open ollimeier opened 6 days ago
https://github.com/googlefonts/fontra/pull/1487#pullrequestreview-2142589832
From Just: Regarding, https://github.com/googlefonts/fontra/issues/1492, we actually have to address this here after all.
You call getSelectionBounds() as part of the draw code as well as on each mouse move. This is fundamentally too much computation for fast drawing, and does a lot of redundant work.
Instead, we should:
Then, use a throttled callback that will do the bounds computation, and store the computed bounds in a property of the scene model, and request a canvas update.
(Throttled: limit the number of callback calls per second, there's a helper func for that)
Further note from Just: We will separate:
Computation stores the current selection bounds in a scene model attribute. The rest of the code will use that attribute, unless it’s undefined.
The following page demos a great way of how we can analyze the performance: https://developer.chrome.com/docs/devtools/performance
There is a nice tool build into chrome which let's you slow down the CPU and record a profiling which give you hints if the performance is harming the user experience.
potential performance regression with complex outlines
Just: I think we may have a bit of a performance problem with (very) complex outlines, as the relatively expensive getSelectionBounds() call is performed at every mouse move. I’m not yet sure what to do about it, maybe we need to followup with some optimizations. While the outline is not changing and while the selection is not changing, the getSelectionBounds() call will always return the same.