Live data from Hacker News

Don't animate height

granola.ai

81–90 of 276 posts

Re: Don't animate height

#81
post #69

ironic that the benefit of using web tech (platform abstractions) can be totally negated by such a small footgun, which then requires insane knowledge of the browser rendering pipeline to solve

None of this should be esoteric knowledge if you work with web technologies for a living. Animations, box shadows and blurs have a very long history of performance issues. Similarly, standard tools easily highlight the issue, as shown in the article.

Re: Don't animate height

#82
post #12

I would also suggest looking into the following in this case: https://developer.mozilla.org/en-US/docs/Web/CSS/contain https://developer.mozilla.org/en-US/docs/Web/CSS/will-change There are hints you can provide to the browser that may have an impact in scenarios where you are animating layout properties.

CSS contain has made so many performance "truths" obsolete, but so few developers realize it. I've seen massive efforts to do things like port text editors to WebGL where rasterizing text is a huge pain where putting `contain: content` on the individual elements in the DOM version would have delivered most of the perf improvements.

Browser rendering engines are now sophisticated GPU-accelerated compositors. Absolute positioning with contain: strict removes basically all CSS layout from the perf equation, and you don't have to write your own compositor or line-layout! `* {contain: content}` and flex/grid gets you the good parts of HTML and very good performance.

Re: Don't animate height

#83
This looks like a clever implementation of a useful feature. I enjoyed that the developer was able to link the streaming audio API to a useful visualizer, recognize problems with his approach, debug issues in that visualizer, and find a clever solution using graphics fundamentals like masking.

I'm less than impressed with the general consensus that he's somehow negligent for launching a feature that needed a fix, or that users don't want or need feedback about audio connectivity, or that the poster did something much better sometime back in `02.

Re: Don't animate height

#84
post #50

Just wrap it in a container with fixed height and "overflow: hidden". Now the layout engine knows that it doesn't need to recalculate positions of elements outside that wrapper, and it's much faster. By the way, the same trick was speeding up large rendering back in the day. As long as you know the size of your rows or columns ahead of time, which kinda defeats the purpose of .

This is the answer. I thought this was fairly common knowledge, height is animated quite often (think dropdowns), no need for the over complications.

Re: Don't animate height

#85
post #33

Is it possible to restrict this as a user? Like to force webpages to use under a certain amount of render/paint time/resources or else just break so that one dumb tab doesn't use up all my battery? Then I can opt-in to greater resources usage if it's a webpage I actually care about. I've seen the "This webpage is using alot of resources" popup before but I don't think it would happen in this case. Because honestly I…

ChromeOS has logic that restricts background tabs to 1% CPU use I think.

Re: Don't animate height

#86
post #23

Is it just me, or have a lot of modern startups lost the plot? Imagine doing all this work for an element of your app which has nothing to do with its feature set. No one cares (certainly no customer) about an audio visualizer bar animation. The post is also riddled with all kinds of misunderstandings, as well. For example, the authoritative language used to describe the differences between layout/painting/compositin…

This was my thinking, too.

Why distract users with giving an auxiliary feature so much prominence? Why wasn’t a GIF enough? Or just an SVG that consists of 3 frames?

Spending this much time on fixing this bug was worthwhile (at least it created a HN front page article) but the solution was not. 6% CPU usage is horrible.

Re: Don't animate height

#87
I read this article because just last week I set up CSS height transitions to show/hide divs in a form which displays conditional content (based on radio button selection). "Why shouldn't I do this?", I thought.

It looks like the point of this article is that you should avoid continuous animation for CPU performance reasons. These performance reasons are probably inconsequential for occasional transitions.

For many of us in the target demographic of "people who animate height", the scary title of this article is misleading.

Re: Don't animate height

#88
post #9

What amazes me is that so much a M2 Mac's resources would be used to render a website even if it rendered everything from scratch. There is almost no graphic content compared to a video game produced decades ago, and they would easily render a frame in 1/2 the time on decades old hardware

Keep in mind that the percentage in Activity Monitor is 100 % per core, so a 10 core CPU can go up to 1000 % usage. So 60 % means 60 % of a single core not of the whole CPU.

Re: Don't animate height

#89
> Instead, we can create the illusion of a changing height by using two rectangles, applying translate to each.

Its a very clever solution and props to the engineer, but this being the fix makes me truly despair at where we are as an industry around web UI. That html and css won despite these sorts of counter-intuitive horrors.

UI layers that make me feel good reflect intent. I can take an image and write some code to darken that image (any image) and show that to the end user. It makes sense. However, in html+css I have to introduce a third element, another rectangle, slap it infront, paint it entirely black and set its opacity to something low. Sure, it works the same but it just feels so conceptually ugly.

Re: Don't animate height

#90

My head is sort of reeling from this. If height animations are that expensive today, imagine how expensive (and still commonplace) they were twenty years ago. I fortunately quit animating height quite a long time ago in favor of similar transform techniques, but… wow, still crazy to learn the magnitude of this common operation.

But it wasn't expensive twenty years ago. Twenty years ago people actually knew how to efficiently use their limited computational resources.
Post reply on HN