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.

Comparing Rust and JavaScript

107 pointsby orixilusalmost 3 years ago

20 comments

montroseralmost 3 years ago
More of a comparison between WebAssembly and JavaScript, really. That the WebAssembly was compiled from Rust is not especially meaningful here.
评论 #32109298 未加载
评论 #32107788 未加载
评论 #32107869 未加载
评论 #32107501 未加载
评论 #32107890 未加载
评论 #32112756 未加载
oefrhaalmost 3 years ago
The difference in performance is about 3x and it looks like an pretty ideal case for wasm. Seems to match observations from Zaplip portmortem:<p>&gt; Rust is faster than JS in some cases, but those cases are rarer than we expected, and the performance gain is on the order of 2x some of the time, not 10x most of the time.<p><a href="https:&#x2F;&#x2F;zaplib.com&#x2F;docs&#x2F;blog_post_mortem.html" rel="nofollow">https:&#x2F;&#x2F;zaplib.com&#x2F;docs&#x2F;blog_post_mortem.html</a>
评论 #32108834 未加载
评论 #32108203 未加载
评论 #32108265 未加载
评论 #32111249 未加载
gwbas1calmost 3 years ago
I wish there was an &quot;about&quot; blurb. Perhaps 2-6 paragraphs explaining what&#x27;s going on?<p>Although it&#x27;s obvious that you&#x27;re comparing JavaScript and WASM performance, the devil is in the details. What <i>exactly</i> are you comparing?<p>There&#x27;s quite a bit of overhead in calling out from WASM to the DOM; how are you making WASM faster? How much &quot;JavaScript&quot; is involved in the WASM version? Are you manipulating a Canvas? Generating a bitmap?
评论 #32108296 未加载
tjelenalmost 3 years ago
The innermost rendering loop in the JS seems to create and destruct an array instance for every single pixel iteration (see <a href="https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;chaos-screen-saver&#x2F;blob&#x2F;master&#x2F;src&#x2F;modules&#x2F;Attractor.js#L79" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;chaos-screen-saver&#x2F;blob&#x2F;master&#x2F;s...</a>). I guess that this could be potentially optimized away by the JIT, but it will make things slower or at least less predictable.
评论 #32107893 未加载
评论 #32108314 未加载
评论 #32112103 未加载
评论 #32107941 未加载
评论 #32108268 未加载
fizzynutalmost 3 years ago
I&#x27;m curious why a lot of people get a 3x improvement. I get about 6.5-7x speed up, which suspiciously lines up with a 60hz vs 144hz framerate...
评论 #32107818 未加载
评论 #32108145 未加载
评论 #32111513 未加载
paulgbalmost 3 years ago
I found the source of each:<p>JavaScript: <a href="https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;chaos-screen-saver&#x2F;blob&#x2F;master&#x2F;src&#x2F;modules&#x2F;Attractor.js" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;chaos-screen-saver&#x2F;blob&#x2F;master&#x2F;s...</a><p>Rust: <a href="https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;rust-wasm-attractor&#x2F;blob&#x2F;master&#x2F;src&#x2F;lib.rs" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;dmaynard&#x2F;rust-wasm-attractor&#x2F;blob&#x2F;master&#x2F;...</a>
liminalalmost 3 years ago
Interestingly Firefox is faster for both JS and WASM. I&#x27;m seeing:<p><pre><code> 1247 px&#x2F;ms Chrome JS 1681 px&#x2F;ms Firefox JS 5878 px&#x2F;ms Chrome WASM 6382 px&#x2F;ms Firefox WASM</code></pre>
评论 #32109593 未加载
评论 #32111088 未加载
AtNightWeCodealmost 3 years ago
My conclusion from this is that Firefox seems to be much faster than Chrome-based browsers when it comes to WASM. I have noticed this trend before.<p>I would be more interested in a more realistic test with scenarios replacing web frameworks like React. This benchmark seems more like something you would do with shaders anyway.
gudmundvatnalmost 3 years ago
When comparing js and wasm, one thing people rarely mention is that with js, you get built-in functions&#x2F;runtime (without crossing the boundary and then getting language mismatch). When &quot;reimplementing&quot; that functionality in wasm, it will add a good amount to binary size. Just a hashmap will add a decent bit. Not to say there aren&#x27;t uses, but js comes with some advantages.
jollybeanalmost 3 years ago
I feel this is a bit of an &#x27;algorithmic fallacy&#x27;.<p>If you have a few algs. you need to run under the hood, preferably with few cross domain calls, that can be expressed mostly using a small bunch of native types and not a lot of maps&#x2F;string etc. then something low-level like WASM might help.<p>But that doesn&#x27;t match most real world scenarios very well.
评论 #32109353 未加载
qsortalmost 3 years ago
I get that the intended meaning is &quot;JS sux&quot;, but I can&#x27;t help being impressed with how performant engines are. The &quot;pixels per ms&quot; count ratio is less than 3:1 on my machine, in what I imagine is a CPU-heavy task.
评论 #32108144 未加载
评论 #32107506 未加载
N-Krausealmost 3 years ago
Can someone explain what exactly I am looking at here? The about page seems to be an empty page for me.
评论 #32107423 未加载
评论 #32107369 未加载
评论 #32107361 未加载
user249almost 3 years ago
Rust is a great solution to the memory safety problem, but is more difficult to use and slower to compile than some other languages. I&#x27;m wondering why I would use Rust for WebAssembly, which doesn&#x27;t have memory safety issues?
评论 #32110808 未加载
评论 #32111270 未加载
评论 #32109626 未加载
usrusralmost 3 years ago
On my phone Firefox I occasionally get a surprisingly stable &quot;Infinity&quot; readout. Am I seeing a timing sidechannel mitigation in the flesh or is that just my news-fed brain imagining explanations?
christophilusalmost 3 years ago
On my iPhone: 2.8K vs 6K (WASM)<p>On my Linux laptop, Firefox: 1.7K vs 3K<p>On my Linux laptop, Brave: 1.5K vs 6K<p>It does seem to vary quite a bit based on the pattern being drawn, though. These ratios seem to roughly hold, but there&#x27;s wide variance.
wdrozalmost 3 years ago
It&#x27;s nice to see how much faster is wasm. This kind of problem would also be nice for parallelization. What&#x27;s the state of multi-threading wasm? any advantage over javascript web workers?
评论 #32108577 未加载
bearjawsalmost 3 years ago
Ah yes, all the 3d websites and 3d information I use regularly.<p>IMO we need to start building UI frameworks that are powered by WASM, and then benchmark those as compared to JS equivalent.
评论 #32111025 未加载
评论 #32110919 未加载
tekkkalmost 3 years ago
Very pretty! Like the demo. Demonstrates well how WASM can overcome these processing bottlenecks.
davidatbualmost 3 years ago
The JS Framework Benchmark compares benchmarks (both WASM and JS) in the more usual setting of DOM manipulations.<p>The link below pre-filters to my subjective &quot;picks&quot; that I think give a birds-eye view of the wasm-to-js comparison for DOM manipulation:<p>My picks, ranked descending by performance: SolidJS &gt; Vue &gt; Sycamore-rs &gt; Svelte &gt; React &gt; Yew<p>SolidJS is a truly reactive JS framework. Sycamore-rs can be taught of as the Rust-clone of SolidJS, and Yew can be taught of as the Rust-clone of React.<p>[0] <a href="https:&#x2F;&#x2F;krausest.github.io&#x2F;js-framework-benchmark&#x2F;current.html#eyJmcmFtZXdvcmtzIjpbImtleWVkL3JlYWN0LWhvb2tzIiwia2V5ZWQvc29saWQiLCJrZXllZC9zdmVsdGUiLCJrZXllZC9zeWNhbW9yZSIsImtleWVkL3Z1ZSIsImtleWVkL3lldy1ob29rcyIsIm5vbi1rZXllZC9hcHBydW4iLCJub24ta2V5ZWQvYXJ0Iiwibm9uLWtleWVkL2F1cmVsaWEiLCJub24ta2V5ZWQvYmRjIiwibm9uLWtleWVkL2JpbmRpbmcuc2NhbGEiLCJub24ta2V5ZWQvY2FsbGJhZy1qc3giLCJub24ta2V5ZWQvY2FsbGJhZy1qc3gtbGlzdCIsIm5vbi1rZXllZC9jcnVpIiwibm9uLWtleWVkL2N5Y2xlanMtZG9tIiwibm9uLWtleWVkL2RhdHVtIiwibm9uLWtleWVkL2RlbG9yZWFuIiwibm9uLWtleWVkL2Rvam8iLCJub24ta2V5ZWQvZG9tZGlmZiIsIm5vbi1rZXllZC9kb212bSIsIm5vbi1rZXllZC9kb29odG1sIiwibm9uLWtleWVkL2RveiIsIm5vbi1rZXllZC9lZi1qcyIsIm5vbi1rZXllZC9lbG0iLCJub24ta2V5ZWQvZW5kb3JwaGluIiwibm9uLWtleWVkL2V0Y2giLCJub24ta2V5ZWQvZmlkYW4iLCJub24ta2V5ZWQvZnJlIiwibm9uLWtleWVkL2hhbG9nZW4iLCJub24ta2V5ZWQvaGVyZXN5Iiwibm9uLWtleWVkL2h1bGxvIiwib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1vbmUtMWsiLCIwN19jcmVhdGUxMGsiLCIwOF9jcmVhdGUxay1hZnRlcjFrX3gyIiwiMDlfY2xlYXIxa194OCIsIjIxX3JlYWR5LW1lbW9yeSIsIjIyX3J1bi1tZW1vcnkiLCIyM191cGRhdGU1LW1lbW9yeSIsIjI1X3J1bi1jbGVhci1tZW1vcnkiLCIyNl9ydW4tMTBrLW1lbW9yeSIsIjMxX3N0YXJ0dXAtY2kiLCIzM19zdGFydHVwLW1haW50aHJlYWRjb3N0IiwiMzRfc3RhcnR1cC10b3RhbGJ5dGVzIl0sImRpc3BsYXlNb2RlIjoxLCJjYXRlZ29yaWVzIjpbMSwyLDMsNF19" rel="nofollow">https:&#x2F;&#x2F;krausest.github.io&#x2F;js-framework-benchmark&#x2F;current.ht...</a>
ricardobeatalmost 3 years ago
These comparisons are always highly biased by the kind of work being done. V8 is so good at optimizing code, it&#x27;s usually possible to reach similar performance in JS.<p>See <a href="https:&#x2F;&#x2F;surma.dev&#x2F;things&#x2F;js-to-asc&#x2F;" rel="nofollow">https:&#x2F;&#x2F;surma.dev&#x2F;things&#x2F;js-to-asc&#x2F;</a><p>Not that relevant, but it looks pretty terrible on a hi-dpi screen, it&#x27;s probably not accounting for the pixel density when creating the canvas. Looks much better on a normal screen.
评论 #32108403 未加载
评论 #32108236 未加载
评论 #32108680 未加载