concrete-utopia / utopia

Design ❤️ Code
https://utopia.app
MIT License
3.75k stars 168 forks source link

Canvas Performance: severe problems with dom-walker, MutationObserver and ResizeObserver #6067

Closed balazsbajorics closed 2 months ago

balazsbajorics commented 4 months ago

When dragging the border radius slider of the PromiseCard component, we can see egregious performance:

Image

The entire render would be bad enough at 55ms, but we accidentally run it twice because an activating MutationObserver and ResizeObserver.

These observers do not create accidental re-renders during on-canvas interactions, which is where we tested them, so that's good.

BUT the entire system is not fine grained and were designed in a more naive time: 1: we invalidate the entire scene, not just the element 2: it's not controlled when should this dom-walker run happen then 3: we should either rely on the observers OR on the canvas interaction, but not both 4: the dom-walker should never walk entire subtrees during interactions

Possible ideas for building a better solution:

TLDR end goal is that during an interaction, we really only call getComputedStyle for a handful of elements, and spend almost zero time on merging large jsxMetadata trees etc. ideally ALL OF the metadata update should take 0.1-0.2ms per frame instead of 7-10ms of today

Rheeseyb commented 2 months ago

@balazsbajorics Is this ticket still relevant?

maltenuhn commented 2 months ago

Note: for labels scrubbing, the performance (at least in vanilla project) is now more than adequate (prob result of #6196 and other performance improvements)

maltenuhn commented 2 months ago

Turns out this actually done not blocked; closing!