102 ms·
Speaking performance/optimisations, interesting choice to destroy canvas when it leaves viewport and recreate it upon each re-entry. Personally I'd leave it cr
by myfonj 5y ago
Speaking performance/optimisations, interesting choice to destroy canvas when it leaves viewport and recreate it upon each re-entry.
Personally I'd leave it created and stop observing the element instead, à la
/* … */ if (entry.isIntersecting) { observer.unobserve(entry.target); /* … */ }
Do you think (or know) that swapping observed node for canvas (potentially producing many canvases) is more expensive than keeping all observers and having smallest possible amount of canvases? (Maybe I'm biased towards saving CPU but saving RAM is better after all?)
- onion2k 5y agoThat's a really good idea. Definitely something to measure, but I suspect you're right.
- eyelidlessness 5y agoIf it turns out there’s some upper bound where caching canvases in memory becomes a problem (eg large threads become not paginated), it’s pretty trivial to build a cache around [Weak]Map and get the ~best of both worlds.