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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Why 1GB RAM in iOS Gives at Par Performance with 3GB Android Phone?

14 点作者 sourcex超过 10 年前

6 条评论

vardump超过 10 年前
I think Java&#x27;s issue is not really due to garbage collection directly, but overuse of references (pointers) leading to very complicated object graphs.<p>This in turn leads to a lot of pointer chasing, cache thrashing and typically significantly higher memory requirements. It&#x27;s sad how bad reputation this has &quot;earned&quot; for garbage collection in general.<p>Even with just a few CPU cores, if you tried to emulate a similar number of object pointers by using reference counting instead of garbage collection, I believe it&#x27;d be at least by an <i>order of magnitude slower</i> than modern GC algorithms. With tens of CPU cores, reference counting would get almost no actual work done. Garbage collection would outperform it by a very large margin.<p>Manual memory management wouldn&#x27;t fare much better, because memory allocation is glacial: &quot;malloc&quot; (and often also &quot;free&quot;) are <i>very</i> slow. Allocators need to traverse a complicated data structure to find a suitable free memory block and to mark it used. Fortunately memory allocation algorithms can at least scale with number of CPU cores.<p>Reference counting is problematic with more than one CPU core. If multiple cores can access the same reference counted object, naive reference counting very quickly saturates CPU core interconnect with cache coherence traffic. Every time a reference count is increased (retained&#x2F;reserved&#x2F;locked) or decreased (released), an atomic operation is required, all cores must have same value in their local caches. The reference count changes need to be communicated to <i>all</i> other CPU cores [1]. This performance penalty can be partially worked around by minimizing number of reference count alterations and by using hacks on top of the simple case, but at cost of complexity and reduction of safety.<p>In Java, you can&#x27;t have an array of Objects, for non-elementary types you get an array of references (pointers) instead, where each array element carries overhead of java.lang.Object. The number of pointers is gigantic in pretty much any JVM heap. This is very bad especially for small objects, which unfortunately tend to dominate nearly any heap.<p>You can of course get around this by &quot;rotating&quot; arrays of Objects. No array of Objects, but Object of arrays. Each semantic Object field becomes an elementary type array in a holder Object.<p>This fixes performance and memory consumption at cost of flexibility, code size and readability.<p>Garbage collection extends the object lifetimes and scales linearly with number of CPU cores, but needs [periodic] housekeeping. Reference counting keeps object lifetimes short, but is unsafe with multiple CPU cores or needs slow atomic operations that result expensive inter-core cache coherence traffic, making it ultimately scale badly.<p>There&#x27;s no silver bullet.<p>[1]: Real cache coherence protocols are quite a bit more complicated than that, see <a href="http://en.wikipedia.org/wiki/Cache_coherence" rel="nofollow">http:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Cache_coherence</a>
评论 #8617924 未加载
评论 #8617967 未加载
ParvusPonte超过 10 年前
Better memory usage due to the (BSD-like) kernel, vs Linux could be one of the factors.<p>&quot;My server earlier used to consume over 1 GB of memory for running PHP, MySQL and Nginx. Now, it doesn’t even touch 500 MB! It’s always less than 500 MB. Everything is just same, configuration, etc. Only OS changed.&quot; <a href="http://nileshgr.com/2013/06/07/the-move-from-linux-to-freebsd" rel="nofollow">http:&#x2F;&#x2F;nileshgr.com&#x2F;2013&#x2F;06&#x2F;07&#x2F;the-move-from-linux-to-freebs...</a><p>Slightly off topic but I really wish mainstream VPS providers start adopting FreeBSD, perhaps <a href="http://labs.online.net/" rel="nofollow">http:&#x2F;&#x2F;labs.online.net&#x2F;</a> can spark that change, I&#x27;d move from Digital Ocean in a heart beat!
评论 #8618012 未加载
vlad超过 10 年前
Besides reasons mentioned in this topic, Apple&#x27;s desktop and mobile operating systems feature memory compression and other algorithms to save memory and battery life for the last year, since Mavericks and iOS 7.<p><a href="http://www.umass.edu/newsoffice/article/key-features-apple%E2%80%99s-new-operating-system" rel="nofollow">http:&#x2F;&#x2F;www.umass.edu&#x2F;newsoffice&#x2F;article&#x2F;key-features-apple%E...</a>
barrystaes超过 10 年前
There is only 1GB of ram in iPads? This explains why the browser keeps crashing when i keep 20 tabs open.. jeez!
paines超过 10 年前
BSD-ish vs Linux Kernel ?
dozzie超过 10 年前
Simple: because of Java.
评论 #8618018 未加载
评论 #8618668 未加载