News for hackers. Stuff that matters.

Ask HN: Does Collapsing an HN Thread in a Popular story spike your CPU use?

For popular threads with a lot of comments, collapsing a top comment leads to high CPU usage and can cause browsers (I tried in Chrome and Vivaldi) to freeze up.

For example, this very popular thread: https://news.ycombinator.com/item?id=43561253&utm_term=comment

If you collapse the top comment, I see a huge spike in CPU and my system freezes temporarily.

Is it just me?

( 22 comments | 6 points | on HN )
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by catgirlinspace on Friday April 04, 2025 @12:09PM (#43584474)
I don't see a CPU usage spike on Safari Technology Preview Release 214.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by superkuh on Friday April 04, 2025 @12:16PM (#43584556)
Nope. I leave javascript turned off like with every other website. No CPU use issues.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by ahofmann on Friday April 04, 2025 @12:24PM (#43584673)
Found the arch user ;-)
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by anenefan on Friday April 04, 2025 @11:49AM (#43584134)
I have an old system with simple older firefox -- It can collapse the given example without even noticing ... well not perceptible to myself ... I'd call it near instantaneous, also tried repeatedly as well as going though collapsing the rest but was unable to cause a falter. I do though have a deny list of sites that provide / contain scripts that snoop too hard as well as a couple I'm suspected set up as resident in the background where the behaviour was only corrected with quit and restart. Mind that deny list results in a few innocent sites not loading up, but I can live with that.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by daemonologist on Friday April 04, 2025 @11:36AM (#43583963)
Not for me - CPU usage remains indistinguishable from idle and any blocking of the main thread is imperceptible. (Firefox 137 on Fedora Gnome 41)
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by whatamidoingyo on Friday April 04, 2025 @11:17AM (#43583660)
It's not just you, it happened to me a few times today. This is the first time this has happened.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by krapp on Friday April 04, 2025 @11:20AM (#43583704)
The javascript that hides collapsed layers probably isn't optimized and doesn't scale up to thousands of DOM nodes well.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by frou_dh on Friday April 04, 2025 @12:18PM (#43584593)
As ever, there's no need to guess what's happening when one has a Profiler on hand.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by kvemkon on Friday April 04, 2025 @12:27PM (#43584710)
It takes approx 13 seconds to finish loading the page with CPU spike and firefox occupies more memory as long as the page remains opened. But then opening/collapsing the thread is not noticeable.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by pixl97 on Friday April 04, 2025 @12:33PM (#43584761)
Chrome and Firefox are instant for me in Windows. No CPU spike.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by mentalgear on Friday April 04, 2025 @12:35PM (#43584776)
Funny enough just this morning, I inspected the memory usage of several of my Firefox tabs, and even though I thought HN as a quite lightweight website, I was surprised to find out that there was about 200 MB per HN tab allocated!
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by DeathArrow on Friday April 04, 2025 @12:36PM (#43584793)
I use Edge on both mobile and desktop. I haven't noticed any spike when collapsing a thread.

Judging from the other commeters who didn't noticed spikes, I think there might be something related to your hardware and software combo that is causing it.

Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by JustSomeRand0 on Friday April 04, 2025 @12:38PM (#43584824)
I can reproduce this consistently in both Edge and Chrome. I've been assuming that it was a change to how Chromium redraws pages that was introduced a few months ago, but I haven't really looked into it. I just started hitting Next instead of collapsing anything.

I just timed it real quick in Edge 134.0.3124.93 and collapsing svara's top level thread hangs the browser and lags my system for 1 minute 36 seconds.

Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by dunham on Friday April 04, 2025 @01:13PM (#43585256)
Interesting, I can't reproduce it. I've got Chrome 134.0.6998.166 on macos and with profiling turned on, it's about 55ms for me (3ms of that is spent in scripting).
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by jeroenhd on Friday April 04, 2025 @12:48PM (#43584953)
I don't see it. It's probably an addon issue. Have you tried running the browser without addons?

I know, for instance, that Dark Reader seems to affect my CPU usage when mass updating DOM elements like that.

And I suppose it depends on your CPU, if you're running modern browsers on a fifteen year old laptop you're going to see CPU spikes all over the place.

Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by dvh on Friday April 04, 2025 @12:52PM (#43585005)
This reminds me that one time on one Czech Linux portal when someone posted blog about crocodile infested river, there were several characters and you were supposed to decide who is more or less moral and judge their behavior in the story. The whole thread became so massive that it brought portal down and even today when you open it it loads half a minute.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by lantry on Friday April 04, 2025 @01:02PM (#43585126)
link please? I want to see this
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by dvh on Friday April 04, 2025 @02:34PM (#43586158)
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by ASalazarMX on Friday April 04, 2025 @06:33PM (#43588425)
Computers have gotten much faster since 2009, but I wanted to experience the original pain, so I made Firefox translate it offline. It huffed and puffed for a few minutes on my weak corporate VD, and it was strangely satisfying.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by anenefan on Friday April 04, 2025 @10:10PM (#43589936)
I still use an older firefox - the thread loaded in less than 10 seconds - I'd say 7 or 8. Maybe they've sorted loading issues, or changed their JS and APIs source / sets. I have an older computer that would have been newish in 2009, so IMHO nothing to do with old computers.
Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by scottlamb on Friday April 04, 2025 @01:06PM (#43585187)
Collapsing the top comment (by svara) in that thread is essentially instant for me, with Chrome 134.0.6998.166 on macOS.

The Javascript is surprisingly readable (not minimized, not using any framework). It looks like all the comments are peers according to the DOM structure. When it collapses a comment, it loops through all the following DOM siblings until returning to the same indent level (so all the semantic descendants) and hides them one-by-one. I could see why this could be a bit slow even though it isn't for me. I'm not really a frontend person so I don't know why they might have chosen this structure. One could imagine if the DOM structure were set up such that the comment's descendants were DOM descendants, it wouldn't have to do this at all. It could just use a CSS selector that would hide elements (and thus their descendants also) if their direct parent were collapsed.

Re:Ask HN: Does Collapsing an HN Thread in a Popular story s... by areyourllySorry on Saturday April 05, 2025 @03:16AM (#43591578)
it is indeed sluggish on my phone the first time i collapse, speeds up after