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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Exploring Lock-Free Rust (2017)

39 点作者 cjg超过 2 年前

4 条评论

judofyr超过 2 年前
Isn’t there a race condition here? Thread 1 acquires the lock, but stalls before it writes the value. Thread 2 will not acquire the lock, but immediately attempt to read the value - which will be None and the unwrap will panic.
评论 #32938727 未加载
评论 #32938657 未加载
eqvinox超过 2 年前
Very interesting, but might need a (2017). Does anyone know if this is still state of the art?
evgpbfhnr超过 2 年前
Also curious how crossbeam compares with e.g. urcu which sound perfect for this kind of many-read-few-updates scenarii (rust&#x27;s urcu crate is a wrapper over the c lib, <a href="https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;urcu" rel="nofollow">https:&#x2F;&#x2F;crates.io&#x2F;crates&#x2F;urcu</a> -- there might be other native implementations somewhere) Doesn&#x27;t seem to be any comparison of the two around that I could find, the algorithm are close but probably different enough to matter?
jeroenhd超过 2 年前
This is the first of a series of three blog posts, with quite an interesting conclusion in the final post[1]:<p>&gt; On my 2012 desktop workstation with 3GHz Xeon W3550, the Java benchmark reports an average of 7.3 ns per getTransformed invocation. The Rust benchmark reports 128 ns in get_transformed, a whopping 17 times slower execution. [...]<p>This article was written five years ago and things may have changed for better or for worse. However, this is an obvious example of how using Rust can make your code slower: by making you implement all the nitty-gritty details yourself (i.e. multi-threaded locking mechanisms), getting everything right and up to speed is left up to you rather than to the standard library, like in Java, where dedicated people have been improving their solution to this problem for decades now.<p>Rust can be lightning fast compared to Java but it&#x27;s worth considering using the &quot;slower&quot; alternative for certain workloads (in this case, many cross-thread operations) to get a performance benefit. All the talk about Rust&#x27;s fearless multithreading does not necessarily make it a good language, merely a less correctness-bug-prone alternative to C++!<p>I&#x27;ve run the benchmarks on my machine with an up-to-date Rust install; to prevent library bugs, I&#x27;ve also upgraded Rusts&#x27;s dependencies to the highest level they&#x27;ll go. For the Java samples, I&#x27;m running Java 18 with the default GC (haven&#x27;t set up 19 yet on my machine).<p>The results are kind of wild. On the Rust side, the consumers take 46-70ns&#x2F;op on my machine while the producer takes 400-800ns&#x2F;op. When I run the Java benchmark, the consumers take a mere 4.71-12.24ns&#x2F;op (10-65x faster!) but the producer takes a whopping 15486-25810ns&#x2F;op, 40-368x slower! I&#x27;ve run the benchmark on Java 8 and there the performance for consumers is even better (3.4-6.4ns&#x2F;op) but the producers continue to be incredibly slow.<p>I&#x27;m not sure what&#x27;s causing this massive difference in performance (the comments on the article suggest that the producing code is triggering GC, which might very well explain the difference) but it&#x27;s an interesting result to note.<p>I&#x27;m sure Java experts and Rust experts will both have suggestions about optimizing this code further to make the samples go faster, of course. Rust&#x27;s multithreaded workloads _can_ be a lot faster (the prime drag race proves that [2]) but I don&#x27;t think that&#x27;s the point of this benchmark.<p>[1] <a href="https:&#x2F;&#x2F;morestina.net&#x2F;blog&#x2F;784&#x2F;exploring-lock-free-rust-3-crossbeam" rel="nofollow">https:&#x2F;&#x2F;morestina.net&#x2F;blog&#x2F;784&#x2F;exploring-lock-free-rust-3-cr...</a><p>[2] <a href="https:&#x2F;&#x2F;plummerssoftwarellc.github.io&#x2F;PrimeView&#x2F;report?id=1997&amp;hi=False&amp;hf=False&amp;hp=False&amp;fi=java~rust&amp;fp=st&amp;fa=&amp;ff=uf&amp;fb=&amp;tp=False&amp;sc=pp&amp;sd=True" rel="nofollow">https:&#x2F;&#x2F;plummerssoftwarellc.github.io&#x2F;PrimeView&#x2F;report?id=19...</a>
评论 #32943014 未加载