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.

Making JavaScript run fast on WebAssembly

215 pointsby 0xedbalmost 4 years ago

19 comments

kodablahalmost 4 years ago
&gt; So how does this work? Before the code is deployed, as part of a build step, we run the JS code using the JS engine to the end of initialization.<p>I also did basically this exact same thing for Go [0] when I realized their initialization in WASM was very heavy[1]. Basically I ran up until the real Go main started which includes a ton of runtime package&#x2F;data initialization, and took a snapshot of the data and baked it back into the WASM and removed all the pre-main code. Granted this was years ago so I don&#x27;t know if it still works on generated code today, but the idea is the same.<p>I think languages compiling to WASM, if they can, should run their initialization code and snapshot the data. A lot of people don&#x27;t realize the number of init instructions to bootstrap a runtime these days. Go alone has thousands of instructions just to initialize the unicode tables. Over 4 million instructions before main were removed from hello-world Go WASM init by pre-processing.<p>0 - <a href="https:&#x2F;&#x2F;github.com&#x2F;cretz&#x2F;go-wasm-bake" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;cretz&#x2F;go-wasm-bake</a> 1 - <a href="https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;26622" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;golang&#x2F;go&#x2F;issues&#x2F;26622</a>
评论 #27373046 未加载
评论 #27371871 未加载
评论 #27374959 未加载
评论 #27383001 未加载
richdoughertyalmost 4 years ago
Here&#x27;s the talk related to the article: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=C6pcWRpHWG0" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=C6pcWRpHWG0</a><p>&gt; Nick Fitzgerald — Hit the Ground Running: Wasm Snapshots for Fast Startup &gt; &gt; Don&#x27;t make your users wait while your Wasm module initializes itself! Wizer instantiates your WebAssembly module, executes its initialization functions, and then snapshots the initialized state out into a new, pre-initialized WebAssembly module. Now you can use this new module to hit the ground running, without waiting for any of that first-time initialization code to complete. This talk will cover the design and implementation of Wizer; discuss its performance characteristics and the scenarios in which it excels and when it isn&#x27;t the right tool; and finally, in the process of doing all that, we&#x27;ll take a closer look at what makes up the guts of a WebAssembly module: memories, globals, tables, etc.<p>Lots of interesting talks at the recent WebAssembly Summit! <a href="https:&#x2F;&#x2F;2021.webassembly-summit.org&#x2F;" rel="nofollow">https:&#x2F;&#x2F;2021.webassembly-summit.org&#x2F;</a>
评论 #27372376 未加载
syrusakbaryalmost 4 years ago
It should probably be named &quot;Making JavaScript to startup fast on WebAssembly&quot;, since the runtime speed is not really improved by their approach.<p>Besides that, I think Wizer [1] is both an elegant and a simple solution to speed up startup times with Wasm. So good work on that!<p>[1] - <a href="https:&#x2F;&#x2F;github.com&#x2F;bytecodealliance&#x2F;wizer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;bytecodealliance&#x2F;wizer</a>
评论 #27375232 未加载
jonny_ehalmost 4 years ago
I&#x27;m so lost. Why are you shipping a JS Engine built for WASM? Wouldn&#x27;t any platform that can run WASM also run JS code?
评论 #27371918 未加载
评论 #27374804 未加载
评论 #27374245 未加载
评论 #27371912 未加载
评论 #27371901 未加载
hsbauauvhabzbalmost 4 years ago
As someone who will shortly need to do two very compute intensive functions in the browser (filtering large datasets (100k+ rows) via client specified queries, and parsing large sting blobs) what is my best option?<p>I’m aware of server side rendering but I suspect the performance in the client may be better responsiveness, with a failover to the server if it’s faster to provide a query response, but is there anything I should _really_ consider for client JS performance at that level?
评论 #27376100 未加载
评论 #27377011 未加载
fabrice_dalmost 4 years ago
Since they are working with SpiderMonkey (Firefox JS engine), I wonder if that opens the door to a Gecko based browser on iOS with decent enough performance. That would be a game changer!
评论 #27372262 未加载
mamcxalmost 4 years ago
This sound tempting.. I&#x27;m building an interpreter (<a href="https:&#x2F;&#x2F;tablam.org" rel="nofollow">https:&#x2F;&#x2F;tablam.org</a>) ad one of the reason is the interpreters are better for exploration&#x2F;repls and such.<p>This looks like it will fix a major point: I could compile everything that is typed and left the rest for runtime.<p>I&#x27;m wondering how much easier could be the life if I compile to WASM to be run on my host...
sandstromalmost 4 years ago
I wonder if the new Wizer component can be used by other projects in the WebAssembly space, e.g. Wasmer?<p><a href="https:&#x2F;&#x2F;github.com&#x2F;wasmerio&#x2F;wasmer" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;wasmerio&#x2F;wasmer</a><p>(Haven&#x27;t fully grasped how they&#x27;re different from wasmtime, but I think they&#x27;ve spend more effort on embedding the runtime into other languages)
vsroyalmost 4 years ago
I think the fact that you can save WASM memory &#x2F; state will yield itself for very powerful applications in the future.<p>I think there&#x27;s a world where true time-travel debugging is possible because you execute your Python program inside of a WASM VM &amp; with WASM, you can save the memory&#x2F;local registers&#x2F;etc. and do true backwards&#x2F;forwards execution.
评论 #27377314 未加载
nielsbotalmost 4 years ago
Reminds of Omega--you wrote scripts to operate autonomous tanks, and pitted your tanks against others&#x27; in an obstacle-filled arena. Omega didn&#x27;t have the realtime scripting component though.<p><a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Omega_(video_game)" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;Omega_(video_game)</a>
评论 #27375595 未加载
评论 #27375574 未加载
skilesarealmost 4 years ago
If anyone out there is involved with this I am very interested and very motivated to figure out if I can get a JavaScript engine running in a DFINITY canister. I just need a compiled wasm and a candid file to try it out. I think. The wasm might need to be compiled in a particular way.
baybal2almost 4 years ago
WASM is slowly, and inevitably becoming Java 2.0, or better to say a new Java VM sans Java.
评论 #27374695 未加载
评论 #27373918 未加载
评论 #27376520 未加载
ficklepicklealmost 4 years ago
I&#x27;m hoping this will be useful for improving react native performance on iOS. Due to restrictions on that platform the JS is currently interpreted and performance is terrible.
rektidealmost 4 years ago
I&#x27;m mostly overwhelmed by excitement &amp; fascination. An amazing effort.<p>Three little notes jump out at me, first:<p>&gt; WebAssembly doesn’t allow you to dynamically generate new machine code and run it from within pure Wasm code.<p>This is a surprise to me. For some reason I thought wasm code could be a SharedArrayBuffer. And I thought that would be mutable. You might maybe have to round trip back to JS to modify this? But I thought it was read-write. I&#x27;m probably wrong but this was quite a surprise to me &amp; a bit of a shocker to hear! Although there&#x27;s good security things you get from this, I didn&#x27;t expect it to be hard set.<p>Second thing that jumps out at me is a little fear. I look at the various projects out there intent on replacing the common DevTools debuggable&#x2F;extension-able web page with a bunch of animated pixels, via use of Canvas, like Google&#x27;s CanvasKit renderer for Flutter. To me, this is scary territory, because it de-empowers the user. This project here has uses far beyond the web, that&#x27;s it&#x27;s real purpose I think (who wants to load the spidermonkey engine compiled to wasm to start running their js on their site), but it still just makes me a little scared of the common DevTools experience fracturing &amp; shattering, into many pieces. This project isn&#x27;t uniquely scary, versus Go on WASM, or Rust on WASM, but it&#x27;s still something I&#x27;m nervous about, and this article made me think of how easy it would be to start making the JS we run considerably harder to wrangle by people writing extensions or enhancing their user agent.<p>Third,<p>&gt; Because the JS engines used to create isolates are large codebases, containing lots of low-level code doing ultra-complicated optimizations, it’s easy for bugs to be introduced that allow attackers to escape the VM and get access to the system the VM is running on.<p>Color me a little skeptical about the virtue of adding another security layer into the virtual machine. I really hope we can get good at isolates, to build blisteringly fast systems, and that we don&#x27;t need to have multiple (or sometimes 1) processes on a computer, each running multiple isolates, each running multiple wasm containers. It&#x27;s a cool capability, but I feel like ideally we&#x27;d be better off with less levels of nesting to get down to the real &quot;process&quot; (process-&gt;isolate-&gt;wasm-container), &amp; better able to trust &amp; leverage &amp; use isolates really well to sandbox work. It seems to be working very very well for those with neat edge tech like CloudFlare Workers.<p>That said, I just did a quick search &amp; a year ago someone was saying V8 isolates take ~3MB of memory each, which is far from insignificant. Developing AOT js-&gt;wasm tech could potentially have a huge memory-saving benefit. Ah, ok, good, the lightweight nature of wizer&#x27;ed containers is emphasized fairly well in this post! It didn&#x27;t leap out at me the first time but it&#x27;s definitely there! This is the core possible advantage, besides simply enabling better exploration of the problem space, which is also key.<p>Fourth,<p>&gt; We started with making initialization fast with a tool called Wizer. I’m going to explain how, but for those who are impatient, here’s the speed up we see when running a very simple JS app.<p>This is a huge focus of this post, and it&#x27;s a great technical marvel. On the other hand, the post talks about the advantages of how Wizer can use snapshots to skip initialization &amp; start with a pre-booted application... the thing is: v8 Isolates can do that too. Deno has been doing quite a lot of work figuring out how to wrangle &amp; manage &amp; make effective use of V8 Isolates snapshots, for example, and that&#x27;s one of the core reasons I think it is an impressively promising advancement &amp; upcoming core technology. Deno is really trying to wrap &amp; better expose the V8 runtime in a better managed fashion, and I think we&#x27;ll see many of the advantages claimed by Wizer start to get reported out the world via Deno as well, over time.
评论 #27373596 未加载
评论 #27374854 未加载
评论 #27377381 未加载
neonatealmost 4 years ago
<a href="https:&#x2F;&#x2F;archive.is&#x2F;CHqkM" rel="nofollow">https:&#x2F;&#x2F;archive.is&#x2F;CHqkM</a><p><a href="https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20210602191646&#x2F;https:&#x2F;&#x2F;bytecodealliance.org&#x2F;articles&#x2F;making-javascript-run-fast-on-webassembly" rel="nofollow">https:&#x2F;&#x2F;web.archive.org&#x2F;web&#x2F;20210602191646&#x2F;https:&#x2F;&#x2F;bytecodea...</a>
saagarjhaalmost 4 years ago
Oh, interesting, it looks like Lin Clark is now at Fastly. I knew I recognized tho at art style…
merbalmost 4 years ago
btw. this could also be interesting for spa applications that do not use node.js on the backend. I wonder when there will be code examples. I would really want to look more into spidermonkey+js in wasm and trying to get spa output.
xkyfalmost 4 years ago
Run quickly*
lypttalmost 4 years ago
I find it interesting they compiled SpiderMonkey to WASM to run JS in its interpreter mode when it already has iOS support built-in via the interpreter. I would&#x27;ve thought all of the performance enhancements could be done without involving WASM at all. As far as I&#x27;m aware the only reason why Firefox for iOS doesn&#x27;t use SpiderMonkey is App Store restrictions.
评论 #27373658 未加载