ZeeCoder / use-resize-observer

A React hook that allows you to use a ResizeObserver to measure an element's size.
MIT License
651 stars 42 forks source link

Use a single ResizeObserver instance #24

Closed ZeeCoder closed 3 years ago

ZeeCoder commented 4 years ago

Seems like it's more performant and the recommended pattern: https://github.com/WICG/ResizeObserver/issues/59

alatielle commented 4 years ago

Related – https://github.com/ZeeCoder/use-resize-observer/pull/26

ZeeCoder commented 4 years ago

I'm not convinced yet whether this is an optimisation that's actually worth it or not. I've only seen a single benchmark that seem to indicate that it might be better to use a single RO for all hook instances, but it wasn't convincing enough to warrant the associated work.

I'd need a way to test this somehow for myself for a large number of observed elements and measure CPU / memory usage maybe, to see if there's a difference between using one or many RO instances.

ZeeCoder commented 4 years ago

Or if there was a comprehensive test / article / benchmark that demonstrated that using a single RO instance is significantly better, then I would consider it.

ZeeCoder commented 3 years ago

I forgot about this one: https://github.com/que-etc/resize-observer-polyfill/issues/13#issuecomment-304648939

Seems like there's something in there, but I'd still need a way to benchmark CPU + memory usage, so that I could compare a results of the current implementation to one that uses a single instance.

ZeeCoder commented 3 years ago

I'd really appreciate someone well-versed in benchmarking UI to help out.