5 ms·
> Rust can even run on the browser, by compiling to WebAssembly . Forgive my ignorance (I haven't done front end web dev in almost a decade), but what is the u
by notRobot 6y ago
> Rust can even run on the browser, by compiling to WebAssembly .
Forgive my ignorance (I haven't done front end web dev in almost a decade), but what is the use case for WebAssembly? What does it enable websites to do that (1) needs to be done within browsers and (2) can't be done with JS?
Also, are there any prominent websites that use WebAssembly? It's shipped with all browsers, but what percentage of users ever make use of it?
- shrumm 6y agoFigma does, and they cut their load time down by 3x. As a frequent user, I can attest to how snappy it feels despite the heavy computations it needs to do in the background. Evan Wallace, their CTO did a great write up on it [1]. [1] https://www.figma.com/blog/webassembly-cut-figmas-load-time-by-3x/ https://www.figma.com/blog/webassembly-cut-figmas-load-time-...
- k__ 6y agoI find it strange when people say "cut by 3 times" What they did was cutting it to 30% or by 70%.
- nicoburns 6y agoIt depends if you think additively or multiplicatively: newLoadTime = oldLoadTime - (70% of oldLoadTime) newLoadTime = oldLoadTime / 3 Personally I find the additive expression unintuitive and find the multiplicative expression easier to reason about. "cut by" does generally indicate an additive expression. It should really have been phrased as something like "reduced by a factor of 3"
- cedex12 6y agohum, aren't both of your assignments the same (modulo 3.3%) ?
- nicoburns 6y agoYes, that's my point. You can phrase the same computation in both ways.
- k__ 6y agoBut it isn't a factor.
- nicoburns 6y agoIt is. Factor, noun "a number or quantity that when multiplied with another produces a given number or expression." It's not an exact integer factor, but I think the concept of factor is more general than that.
- deleted 6y ago[deleted]
- wongarsu 6y ago>It's not an exact integer factor That would imply the phrase has to be "reduced by a factor of 1/3", which leads to the wrong impression. The better technically correct phrase would be "reduced by a divisor of 3"
- the8472 6y agoIf you reduce it by a multiple > 1 of its total time it must be negative, i.e. it's giving you back CPU cycles every time you execute it. Quite impressive.
- eloisius 6y agoI’m also curious about how valuable writing rust that compiled to webasm is. Wouldn’t I still have to write a lot of un-rust-like code to manipulate the DOM? I could definitely see writing a core library in rust and wrapping it in a thin interface to use it in JS, though. Is that the idea?
- johncolanduoni 6y agoThe stand-out uses of WebAssembly have mostly been augmenting a JavaScript application that has strenuous computation needs in certain parts. As others have mentioned Figma, Twitch, etc. have used it to great effect without rewriting their entire app in Rust or another linear-memory based language.
- brohee 6y agohttps://tech.ebayinc.com/engineering/webassembly-at-ebay-a-real-world-use-case/ https://tech.ebayinc.com/engineering/webassembly-at-ebay-a-r...
- hknd 6y agohttps://webassembly.org/docs/use-cases/ https://webassembly.org/docs/use-cases/ TL;DR: - "almost fast as native code for web browsers” - in case you wanna do some expensive computing without a server - "Compiling Existing Applications for the Browser" - port existing code into the browser (eg cpp apps)
- arethuza 6y agoUsing webasm as a general purpose platform for the execution of untrusted code is also pretty interesting - this might be within server side code or non-browser desktop apps.
- m12k 6y agoIt's a way to do things in the browser that you normally can only do with JavaScript but with better performance and written in a different language
- tester34 6y agoYou can use existing e.g C# libraries on the client side (browser) e.g you can develop parser in console application and then ship it to the browser and use it there to parse e.g code without changing a single line of code or having to do some bullshit or traspiling it to js. Once it matures it will allow you to get rid of writing javascript and use java, c#, rust, c++ and many other to write frontend.
- secondcoming 6y agoBasically, multithreaded adverts.
- deleted 6y ago[deleted]
- sbelskie 6y agoThe main thing it can do that can’t be done with JS is not having to use JS. More seriously, one of the main draws is being able to us the same language on both the front and back end, which might be beneficial to reduce the need to duplicate model or just to be able to develop on the front end in ones preferred language.
- kevingadd 6y agoAmong other things, wasm has access to float32, int64 and vector types that JS does not. It also has operations like reinterpret_cast that you can't do in JS without a store/load pair using a scratch buffer.
- aikah 6y agoJS does have BigInts though https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- maleldil 6y agoParent referred to int64. BigInt and int64 are not the same thing. JS doesn't have integers; all numbers are represented as doubles. One of the reasons having actual integers is important is performance, as integer operations are often faster than floating point operations. BigInt doesn't help with that.
- ben-schaaf 6y agoMy use case is having written a compiler/interpreter in rust wasm lets you easily set up a playground for the language.
- kthxb 6y agoIt's purpose is not to replace JS, but to extend it. For example for the performamce critical parts of applications. It is already used in big JS libraries (such as Hyphenopoly, Google's Draco or Long.js) and in lots of custom applications like the Twitch.tv media player and many 3D visualizations.
- threeseed 6y agoOne example is source maps. I have a web app where every time there is an error on the client side it sends it back to the server. On normal JS it locks up the browser for 10+ seconds. In WASM it's instant. Never found another use except for this.
- tester34 6y ago>On normal JS it locks up the browser for 10+ seconds Weird, I think I do the same thing (global exception catcher) and it works fine
- Closi 6y ago> what is the use case for WebAssembly? I think the core use case is "Being something that's not Javascript". The desktop programming world gets benefit from having multiple languages that suit different use-cases, so why would the web not?
- pansa2 6y ago> what is the use case for WebAssembly? Personally, it allows me to write tools that can run either on the command line or in the browser. Only the user-interface need be rewritten - internally both versions can share a lot of code. WebAssembly makes it possible to do this using a language other than JavaScript. However, the languages I can use are still limited - AFAIK WebAssembly is currently only well-supported by C, C++ and Rust.
- sradman 6y ago> what is the use case for WebAssembly? There is no access to the DOM and the POSIX-like WASI interface is limited so the main use case is reusing code with manual memory management (C, Rust, etc). WebAssembly also targets server-side JavaScript runtimes like Node, Deno, and Cloudflare Workers.
- k__ 6y agoI saw that performance became more uniform with Rust/WASM. Not faster all over, but less slow in the worst cases.
- jlg23 6y agoAt the very minimum you can reuse the code for input validation on the server side in the client. Given that those, if maintained separately, tend to diverge, in my experience, this is a net win.
- akudha 6y agoSame questions, plus one more. Can anyone share a good resource that they have used to learn WebAssembly?
- arrayjumper 6y agoI used wasm for a computer vision related feature we built at work. It allowed us to reuse a bunch of things from opencv without having to reimplement those things in JS.