News for hackers. Stuff that matters.
Re:Show HN: HN Avatars in 357 bytes by myfonj on Monday March 14, 2022 @06:30AM (#30670661)
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?)
Re:Show HN: HN Avatars in 357 bytes by onion2k on Monday March 14, 2022 @06:34AM (#30670689)
That's a really good idea. Definitely something to measure, but I suspect you're right.
Re:Show HN: HN Avatars in 357 bytes by eyelidlessness on Tuesday March 15, 2022 @01:09AM (#30681868)
If 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.