TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Why is collapsing a Hacker News comment so slow?

190 pointsby thewarpaintalmost 6 years ago

16 comments

pg_botalmost 6 years ago
I would use the &lt;details&gt; tag to solve this problem. Most people don&#x27;t know this exists and I have no idea why. You would probably have to rewrite the html so it no longer uses tables but I don&#x27;t really consider that to be a negative.<p>I would also question why we are saving collapsed comments. I feel like this is something that doesn&#x27;t need to be persisted forever. If you want this behavior why not use local storage instead?
评论 #20337614 未加载
评论 #20337542 未加载
评论 #20338446 未加载
评论 #20338041 未加载
评论 #20342934 未加载
评论 #20337881 未加载
评论 #20339632 未加载
评论 #20339222 未加载
评论 #20340208 未加载
评论 #20338384 未加载
评论 #20340571 未加载
polotealmost 6 years ago
Fun fact<p>In a previous company we were building a session replay tool, and as you may know it is pretty complex to evaluate the impact of the single script on a page.<p>The only way we found to test the impact of the script was to execute it on a page with the most mutations on an event, and try to see how much the event was impacted.<p>The only place where we found a heavy use of mutations was the hackernews page that had more than 100 comments in a thread. And the first time we tested, we tripled the time to collapse the thread
llamathrowawayalmost 6 years ago
&gt; There is also a GET request to <a href="https:&#x2F;&#x2F;news.ycombinator.com&#x2F;collapse?id=1234567" rel="nofollow">https:&#x2F;&#x2F;news.ycombinator.com&#x2F;collapse?id=1234567</a> to save the state of the collapsed&#x2F;expanded comment if the user is logged in, but it&#x27;s an async request so it doesn&#x27;t have an impact.<p>Is this a correct place to use &#x27;GET&#x27;?
评论 #20337078 未加载
评论 #20337063 未加载
评论 #20337658 未加载
评论 #20337477 未加载
评论 #20341737 未加载
评论 #20337175 未加载
Waterluvianalmost 6 years ago
I have a budget moto and HN comments section is completely unusable on Chrome but perfectly smooth on Firefox. Haven&#x27;t explored why.<p>On Chrome any comment section with more than about 100 comments grinds to a halt. If I try to type in a comment there&#x27;s a three second delay waiting for every letter to appear.
评论 #20338367 未加载
评论 #20338292 未加载
enriqutoalmost 6 years ago
I cannot visually notice any delay. It seems instantaneous in my browser.
评论 #20337690 未加载
评论 #20337588 未加载
RBenjaminalmost 6 years ago
Or just use my Greasemonkey&#x2F;Tampermonkey plugin which disables the Hackernews collapsible comments and introduces its own collapsible comments logic, which is much faster and has a variety of convenience features:<p><a href="http:&#x2F;&#x2F;mental-reverb.com&#x2F;creations.php" rel="nofollow">http:&#x2F;&#x2F;mental-reverb.com&#x2F;creations.php</a>
评论 #20338477 未加载
gowldalmost 6 years ago
I suspect the pg answer to this question is &quot;there&#x27;s too much noise on some posts, and deterring interaction with posts of 300+ comments is a feature, not a bug.
评论 #20339823 未加载
abakkeralmost 6 years ago
I am just now realizing that HN comments are collapsible...I wonder if anyone has ever looked at upvote&#x2F;scroll behavior when the collapse button is used vs not? There are a ton of threads where the top comment is also a non-sequitur, but I know when that happens I frequently don&#x27;t scroll past the hundreds of replies to see what the other first level comments are.
评论 #20341684 未加载
someexgamedevalmost 6 years ago
I wrote a browser extension to collapse HN comments past the first depth and ended up just attaching their css classes and setting the sub-comment count myself. It was the fastest behavior I could find at the time for reasons I&#x27;ve since forgotten. I did try to use their existing js but it took forever to collapse the page.<p>Here&#x27;s my collapse code if interested<p><a href="https:&#x2F;&#x2F;github.com&#x2F;a13o&#x2F;disengaged&#x2F;blob&#x2F;master&#x2F;src&#x2F;hacker-news&#x2F;collapse-deep-comments.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;a13o&#x2F;disengaged&#x2F;blob&#x2F;master&#x2F;src&#x2F;hacker-ne...</a>
env123almost 6 years ago
Refined hacker news, anyone? <a href="https:&#x2F;&#x2F;github.com&#x2F;plibither8&#x2F;refined-hacker-news" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;plibither8&#x2F;refined-hacker-news</a>
wierdaaronalmost 6 years ago
A lot could be gained by simply storing the jQuery objects instead of doing the lookups multiple times per method. That’s a lot of unnecessary dom traversal.
ha99jaalmost 6 years ago
That is really ugly code.
评论 #20337088 未加载
oftenwrongalmost 6 years ago
I dug into the collapsing code recently because I wanted to make a script that collapses HN threads by default. In other words, only the top-level comments would be shown at first. To me this makes more sense. If I am interested in continuing a thread, I can expand it. If I am not interested in continuing, I don&#x27;t want to have to scroll past its children.<p>According to the comments here, maybe I would be better off implementing my own collapsing scheme.
bozoUseralmost 6 years ago
In the similar vein, feature request to sort by best&#x2F;new :)
kabwjalmost 6 years ago
It’s fast on Safari mobile but very slow on Firefox desktop. Goes to show many things.
dangusalmost 6 years ago
If you don&#x27;t mind me being negative here for a moment:<p>1. It&#x27;s not your website, why spend so much time and effort on dissecting the issue? If one did this for every webpage they visited it&#x27;d be a more than a full time job.<p>2. Does it really look like Hacker News has had any serious development effort poured into it anytime recently? What incentive does YC have to put time and money into a forum that generates zero revenue?<p>3. Do we really expect web browsing to be pleasant on a 3 year old budget smartphone with a Qualcomm 617?<p>The Moto G4 Plus is solidly in the bottom 25% of phones listed here:<p><a href="https:&#x2F;&#x2F;www.androidbenchmark.net&#x2F;cpumark_chart.html" rel="nofollow">https:&#x2F;&#x2F;www.androidbenchmark.net&#x2F;cpumark_chart.html</a>
评论 #20338382 未加载
评论 #20338334 未加载
评论 #20339455 未加载
评论 #20338329 未加载