TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Drop millions of allocations by using a linked list

223 点作者 jcn大约 10 年前

16 条评论

bcg1大约 10 年前
I&#x27;m not a ruby dev, so I guess maybe my perspective is not that great on this particular issue... but hats off to the dev with the fix, indeed this is how free software collaboration is supposed to work in my opinion.<p>Even the dev with the fix wasn&#x27;t rude about the original problem, he seemed pretty humble about it actually.<p>If you think the Ruby guys are such shitty programmers you should be able to dive into their codebases and find the plethora of problems to show them what&#x27;s up... so either give them a pull request or STFU ;)
评论 #9197308 未加载
评论 #9198813 未加载
评论 #9197089 未加载
jph大约 10 年前
Great pull request. Ruby makes it easy to duplicate data by calling `.dup` or `+`, and this does help with state isolation. But duplication is an expensive operation.<p>Ruby&#x27;s standard libraries don&#x27;t have much support for immutability, or deep cloning, or copy on write, or linking concatenation. There&#x27;s no standard library way to ask for a snapshot of an object.<p>So in the early days for Ruby, an idiom was: if you&#x27;re writing a method that takes a list, and you need to be sure your list doesn&#x27;t change out from under you, then duplicate it, get it working, and if it becomes a bottleneck then optimize it.
rfrey大约 10 年前
I&#x27;m really surprised by the amount of smugness in the comments here. A bit of good-natured teasing, followed by a wheelbarrow full of &quot;ruby-devs&quot; this and &quot;web-devs&quot; that.<p>Take off your Hats of Superior Coding. Any one of us, regardless of honorific titles, could have made this mistake, and you know it. Being steeped in CS Fundamentals does not immunize you against bugs.<p>Congratulations to tenderlove for finding the bug. Remember the details - it&#x27;ll be a great war story in a few years.
评论 #9197314 未加载
评论 #9196754 未加载
评论 #9197214 未加载
评论 #9198191 未加载
评论 #9197175 未加载
mbrock大约 10 年前
Semi-related: does anyone know why installing gems is so ridiculously slow? What is the thing doing? Downloading tarballs, yes, but then? It&#x27;s a dynamic language; there is no compilation or verification! Why can I install Ruby packages using apt almost immediately, when gem&#x2F;bundle install takes half a coffee break?<p>I&#x27;m growing more impatient with the years. I have measured out my life with slow software. We talk about saving developer time with dynamic languages, but, as Flight of the Conchords sang, <i>the sneakers don&#x27;t seem to get much cheaper; what are your overheads?</i>
评论 #9197403 未加载
评论 #9196657 未加载
评论 #9196661 未加载
评论 #9198428 未加载
评论 #9198180 未加载
评论 #9196723 未加载
评论 #9196842 未加载
kilotaras大约 10 年前
I&#x27;m torn on this one. It&#x27;s a great performance improvement, but on the other hand I would expect this way sooner than after almost 4 years of usage.
评论 #9196450 未加载
mjs大约 10 年前
Are there any profiling tools that would have found this? Flame graphs showing the time spent in traverse, perhaps?<p>It seems like this should have been trivially detectable, since the difference is so dramatic.
noir_lord大约 10 年前
It&#x27;s always nice when a small change is a big win.<p>This reminds me of the gc_disable() PR that reduced composer install times by half a few months back.
评论 #9197960 未加载
cranium大约 10 年前
All your tests passed, nothing broken, a small bit of code for tremendous optimization,... I can feel the satisfaction!
kendallpark大约 10 年前
&quot;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%&quot;<p>--Donald Knuth
icebraining大约 10 年前
I&#x27;m not very familiar with Ruby; where exactly did the duplication occur in the original code?
评论 #9196344 未加载
评论 #9196334 未加载
airblade大约 10 年前
So many armchair critics!<p>It&#x27;s very easy to pontificate in hindsight when somebody else has done the hard work of actually finding something that can be improved.
steipete大约 10 年前
Ruby people discovering algorithms <i>ducks</i>
评论 #9198339 未加载
评论 #9196434 未加载
评论 #9196775 未加载
评论 #9197462 未加载
评论 #9196224 未加载
评论 #9196756 未加载
shiggerino大约 10 年前
Nobody show this to Bjarne Stroustrup <a href="https://www.youtube.com/watch?v=YQs6IC-vgmo" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=YQs6IC-vgmo</a>
评论 #9196510 未加载
评论 #9196623 未加载
chatman大约 10 年前
Just comes to show how careless Ruby guys were while building this.
评论 #9196217 未加载
评论 #9196704 未加载
jokoon大约 10 年前
I still can&#x27;t see the real usefulness of linked lists, the idea of having a data container that doesn&#x27;t have a transparent indexing algorithm sounds ill-advised.<p>Linked lists should be named &quot;linked graphs&quot; instead.<p>There is so much relevant science to learn about CPU caches, than there is about using a container which is based on nested pointer indirections.
评论 #9197483 未加载
评论 #9197050 未加载
评论 #9197349 未加载
voidhorse大约 10 年前
Good job, tenderlove, that&#x27;s a nice performance boost.<p>Personally, I really dislike Ruby&#x27;s syntax, though I haven&#x27;t spent a huge amount of time with it (because I dislike the syntax). The use of bracers and other lexical markers makes code a lot clearer and faster to decipher, imo, than a bunch of def and ends. (I know that () are optional in Ruby, can you also use {} if you desire? Again, not 100% familiar with the language features. Just know some standard rails implementations of the language).<p>Maybe it just hasn&#x27;t &#x27;clicked&#x27; with me yet, but bleh. The dynamic typing doesn&#x27;t help its case in my book either. That&#x27;s my personal preference, and why I try to avoid using ruby, even for the web backed by rails despite it&#x27;s popularity. Then again, if you need to get a web project up and running quickly rails is never a bad choice (in my experience).
评论 #9197384 未加载