News for hackers. Stuff that matters.
Re:Is Rust web yet? by notRobot on Friday October 30, 2020 @06:42AM (#24940907)
> 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?

Re:Is Rust web yet? by shrumm on Friday October 30, 2020 @06:45AM (#24940927)
Figma 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-...

Re:Is Rust web yet? by k__ on Friday October 30, 2020 @07:10AM (#24941058)
I find it strange when people say "cut by 3 times"

What they did was cutting it to 30% or by 70%.

Re:Is Rust web yet? by nicoburns on Friday October 30, 2020 @07:24AM (#24941118)
It 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"

Re:Is Rust web yet? by cedex12 on Friday October 30, 2020 @08:18AM (#24941439)
hum, aren't both of your assignments the same (modulo 3.3%) ?
Re:Is Rust web yet? by nicoburns on Friday October 30, 2020 @08:30AM (#24941529)
Yes, that's my point. You can phrase the same computation in both ways.
Re:Is Rust web yet? by k__ on Friday October 30, 2020 @07:26AM (#24941132)
But it isn't a factor.
Re:Is Rust web yet? by nicoburns on Friday October 30, 2020 @07:31AM (#24941154)
It 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.

Re:Is Rust web yet? by wongarsu on Friday October 30, 2020 @08:05AM (#24941340)
>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"

Re:Is Rust web yet? by the8472 on Friday October 30, 2020 @07:31AM (#24941156)
If 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.
Re:Is Rust web yet? by sbelskie on Friday October 30, 2020 @06:48AM (#24940951)
The 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.

Re:Is Rust web yet? by kthxb on Friday October 30, 2020 @06:54AM (#24940979)
It'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.
Re:Is Rust web yet? by pansa2 on Friday October 30, 2020 @07:09AM (#24941050)
> 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.

Re:Is Rust web yet? by Closi on Friday October 30, 2020 @07:08AM (#24941043)
> 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?

Re:Is Rust web yet? by tester34 on Friday October 30, 2020 @06:48AM (#24940945)
You 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.

Re:Is Rust web yet? by ben-schaaf on Friday October 30, 2020 @06:50AM (#24940960)
My use case is having written a compiler/interpreter in rust wasm lets you easily set up a playground for the language.
Re:Is Rust web yet? by eloisius on Friday October 30, 2020 @06:45AM (#24940928)
I’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?
Re:Is Rust web yet? by johncolanduoni on Friday October 30, 2020 @07:00AM (#24941018)
The 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.
Re:Is Rust web yet? by brohee on Friday October 30, 2020 @06:46AM (#24940934)
Re:Is Rust web yet? by m12k on Friday October 30, 2020 @06:47AM (#24940941)
It'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
Re:Is Rust web yet? by sradman on Friday October 30, 2020 @07:09AM (#24941052)
> 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.

Re:Is Rust web yet? by kevingadd on Friday October 30, 2020 @06:49AM (#24940957)
Among 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.
Re:Is Rust web yet? by aikah on Friday October 30, 2020 @06:57AM (#24940993)
Re:Is Rust web yet? by maleldil on Friday October 30, 2020 @08:12AM (#24941379)
Parent 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.

Re:Is Rust web yet? by threeseed on Friday October 30, 2020 @06:59AM (#24941011)
One 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.

Re:Is Rust web yet? by tester34 on Friday October 30, 2020 @07:00AM (#24941017)
>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

Re:Is Rust web yet? by jlg23 on Friday October 30, 2020 @07:35AM (#24941169)
At 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.
Re:Is Rust web yet? by arrayjumper on Friday October 30, 2020 @09:51AM (#24942163)
I 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.
Re:Is Rust web yet? by k__ on Friday October 30, 2020 @07:17AM (#24941096)
I saw that performance became more uniform with Rust/WASM. Not faster all over, but less slow in the worst cases.
Re:Is Rust web yet? by akudha on Friday October 30, 2020 @08:24AM (#24941483)
Same questions, plus one more. Can anyone share a good resource that they have used to learn WebAssembly?
Re:Is Rust web yet? by hknd on Friday October 30, 2020 @06:46AM (#24940935)
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)

Re:Is Rust web yet? by arethuza on Friday October 30, 2020 @06:49AM (#24940952)
Using 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.
Re:Is Rust web yet? by secondcoming on Friday October 30, 2020 @06:48AM (#24940949)
Basically, multithreaded adverts.