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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

3.7X speedup from removing a call to sleep

150 点作者 nexneo超过 12 年前

15 条评论

othermaciej超过 12 年前
I am the one who originally added this sleep call to WebKit, when we first imported TCMalloc to use as our custom allocator. It was indeed there for a reason, but that reason is not applicable to WebKit's allocation patterns. TCMalloc was designed for a server workload, over time we have adapted it more to the unique needs of a browser engine. This change may help other operations, but probably not as much as the GC benchmark in question.
评论 #4468151 未加载
edw519超过 12 年前
True story...<p>Client gives me a Help Desk Ticket. User claims batch job use to run in 5 minutes but now runs for hours. The logs confirm this. The commit logs show that an offshore programmer forgot to remove a 10 second sleep command from inside an iteration (for debugging I presume) before promoting to production. I removed it and got a 100X improvement in throughput.<p>My client said that now his user loves him; what did I do to fix it so fast?<p>When I told him that I removed the Sleep, he said, "No! No! No! Change it to a 5 second Sleep so I have something to give him the next time he complains!"
评论 #4466880 未加载
评论 #4466871 未加载
评论 #4466957 未加载
评论 #4468622 未加载
pmjordan超过 12 年前
It's interesting how spinlocks are making a comeback in user space code. They are widely used in kernel code, but their use has previously been discouraged in application code. As this example illustrates, it's pretty easy to get them wrong...
评论 #4466831 未加载
评论 #4467339 未加载
评论 #4466800 未加载
grimebox超过 12 年前
Anyone wanna supply some context? I have no idea what is going on here
osivertsson超过 12 年前
It was "only" on one particular benchmark, still it shows that profiling often give you surprising results that nobody familiar with the code anticipated.
cpeterso超过 12 年前
Why did they roll their own spinlock implementation in the first place? They could encapsulate the lock primitives provided by, and optimized for, each platform: CRITICAL_SECTIONs on Windows, futexes on Linux, and pthread_spin_locks elsewhere. iOS and OSX have some Mach-specific spinlocks (OSSpinLockLock?), but I don't have any experience using them.
zizee超过 12 年前
So if I understand this correctly the 3.7x speedup is a speedup in garbage collection and will have a positive effect on the speed of the browser which is nice.<p>But what sort of effect will this have on page rendering? Anyone in the know care to comment on the specifics?<p>edit: improvements to my shoddy wording.
评论 #4466808 未加载
评论 #4467569 未加载
swah超过 12 年前
Are sleeps() always necessary in multithreaded programming?
评论 #4467286 未加载
评论 #4467157 未加载
aristidb超过 12 年前
There was a long comment before the sleep. It seems likely that the sleep was there for a reason.
jrockway超过 12 年前
To be fair, it's a sleep(0), which I assume is just the easiest way to get the process to context switch. I assume this is a speed improvement only when locks become ready sooner than a context switch.<p>The real fix would be to make context switches faster, this is just a data-driven tweak rather than a general solution.
subhro超过 12 年前
Awesome!! I wonder when this is going to get pushed to mainstream Safari.
评论 #4466787 未加载
评论 #4466796 未加载
评论 #4466920 未加载
tlrobinson超过 12 年前
Reminds me of "the speedup loop": <a href="http://thedailywtf.com/Articles/The-Speedup-Loop.aspx" rel="nofollow">http://thedailywtf.com/Articles/The-Speedup-Loop.aspx</a>
duncanwilcox超过 12 年前
The code is, appropriately, in the WTF directory.
chris_wot超过 12 年前
What's with the old comment "// Sleep for a few milliseconds", followed by the sleep function?
khet超过 12 年前
Reduced the number of lines in the code base AND improved the product? nice.
评论 #4472371 未加载