News for hackers. Stuff that matters.
Re:Wgpu-rs on the web by echelon on Thursday April 23, 2020 @05:13AM (#22954120)
This is why Rust is going to eventually eat Javascript's lunch on the browser. I'm willing to longbets that by 2025 we see a Rust framework as the top browser toolkit. I'd even be willing to bet that there are popular frameworks in use by major websites that discard the DOM altogether for something simpler and faster.

There's a reason why this has to happen, too.

My sincere hope is that Mozilla and the Rust/Browser luminaries will develop cross-platform APIs for full device hardware abstraction. If we can get Rust/WASM to be able to access the same system calls, hardware resources, payment APIs, native windowing routines, etc. as the iOS and Android SDKs, then we can potentially build a cross-platform native web that is just as snappy as the two shitty walled gardens we have today.

I really hope the performant web slays the app store. That's the dumbest trap we ever fell for. I'd love to visit a website and be playing native Minecraft in seconds. Sans Google Play or the App Store, with no bullshit monopoly tax.

That would address one of the major problems in our industry.

Re:Wgpu-rs on the web by chrismorgan on Thursday April 23, 2020 @05:44AM (#22954278)
What do you mean by “browser toolkit”? If you mean “thing that people make web apps with” (like React or like you might imagine Qt being, though it’s not for the web platform), there is not a chance that this will happen by 2025. Zero.

For starters, Rust: Rust is just too complex to be the most popular language when something like JavaScript exists which is faster and easier to get started with, and generally good enough. It has niche usage and will steadily grow, but it’s not going to take over the space any time soon, and probably never will. I say this as a Rust developer for seven years and a web developer for more than fifteen years.

Then the other part, discarding the DOM altogether: there are way too many pieces of functionality that the browser provides that currently cannot be implemented in web user space, for this to become mainstream any time soon. For example: correct scrolling, standard keyboard and mouse event handling, and accessibility. The idea that you would go from quite a few pieces of major functionality completely non-existent in browsers and specs (most of these issues aren’t even being talked about) to mastery of the space within five years is unreasonable.

For further shared abstractions, many web APIs are developed and continue to be developed. Other experiments like WASI exist. WebAssembly has scope to be a solid foundation for this sort of thing. But applying all of the interesting web APIs to desktop and mobile platforms, that’s not really something that Mozilla, Rust or browser developers can or should do anything about. They have somewhere between no and extremely limited clout in such spaces.

Re:Wgpu-rs on the web by exomancer on Thursday April 23, 2020 @08:14AM (#22955091)
Rust already has [React-like web framework](https://github.com/yewstack/yew) with a macro for [declarative components](https://github.com/yewstack/yew/blob/ce020d6eb8409b2063cc150...) that compiles to wasm and, last I checked, [runs circles around JS frameworks](https://github.com/DenisKolodin/todomvc-perf-comparison).

I agree that it won't reach the popularity levels of JS due to the learning curve, but on technical side of things future is _now_.

Re:Wgpu-rs on the web by leeoniya on Thursday April 23, 2020 @08:34AM (#22955240)
yew doesnt run circles around anything:

https://krausest.github.io/js-framework-benchmark/current.ht...

wasm-bindgen seems to do well, though its code is rather imperative.

Re:Wgpu-rs on the web by jstarry on Wednesday April 29, 2020 @11:34AM (#23020453)
That benchmark run is about a year old. Yew is v0.15 now (v0.7 came out a year ago) and has improved substantially (and has keyed components now).
Re:Wgpu-rs on the web by exomancer on Thursday April 23, 2020 @08:40AM (#22955275)
Fair enough, I've only seen the one benchmark I've linked.
Re:Wgpu-rs on the web by hobofan on Thursday April 23, 2020 @09:24AM (#22955647)
Yew (and comparable Rust frameworks) do however have a pretty slow compile time and with that a horrible debug-cycle. It's so bad that I in general opt for React-in-Yew for prototyping and only reimplement components with more complex state in Rust.
Re:Wgpu-rs on the web by saagarjha on Thursday April 23, 2020 @04:00PM (#22960488)
Do people writing frontend apps really care that much about performance that they'd be willing to switch to Rust? Honest question.
Re:Wgpu-rs on the web by ng12 on Thursday April 23, 2020 @04:29PM (#22960902)
Not likely. The only thing that really matters to me is developer ergonomics. I've never seen a project struggle because it couldn't render a table with a 1,000 rows fast enough. I have seen many projects struggle because they hired a bunch of junior engineers who had difficulty writing clean, maintainable JavaScript.

Rust and WASM will definitely take on for doing things like WebGL. I can't imagine Rust becoming the de-facto solution for building UIs.

Re:Wgpu-rs on the web by krcz on Thursday April 23, 2020 @05:55AM (#22954322)
I don't think that's going to happen and I hope that's not going to happen. DOM provides good abstraction of UI elements, which helps with accessibility, scrolling behaviour with the same feel as OS, standard text utils like selection, copy-paste. Using many incompatible libraries for that would lead to neo-Flash nightmare.

What I believe is going to happen is splitting more complex web applications into frontend part - written in JS - and backend + graphics part - provided as Wasm, possibly written in Rust.

Re:Wgpu-rs on the web by gameswithgo on Thursday April 23, 2020 @09:44AM (#22955874)
>DOM provides good abstraction of UI elements

Does it, or do we just have a whole generation of people used to that abstraction, who can't imagine anything better?

Re:Wgpu-rs on the web by MaxBarraclough on Thursday April 23, 2020 @09:53AM (#22955976)
It fundamentally doesn't do what UIs need it to. That's why most web UI frameworks use a 'VDOM'. When a framework finds a clever way to avoid doing this (Svelte), we all applaud the accomplishment. I think that gives us our answer. </snark>
Re:Wgpu-rs on the web by p1necone on Thursday April 23, 2020 @05:34AM (#22954233)
https://www.destroyallsoftware.com/talks/the-birth-and-death...

This is becoming (somewhat) more true every day.

Re:Wgpu-rs on the web by smichel17 on Thursday April 23, 2020 @07:05AM (#22954678)
> I really hope the performant web slays the app store. That's the dumbest trap we ever fell for. I'd love to visit a website and be playing native Minecraft in seconds. Sans Google Play or the App Store, with no bullshit monopoly tax.

I don't, unless certain criteria are met.

There is a consumer-friendly side of apps that is often overlooked in these types of conversations: generally, I get to decide when to update my apps, and the developer can't uninstall their app off my phone without my permission. Moving from apps to the web shifts the balance of power even further from user to developer.

There are some apps (that require internet access) for which this is not true. For those, I share your sentiment; spotify has no reason to be an app. It's also possible to implement this amount of user control with the web, by caching the full version of a page, when you add it to your home screen (for example), and only replacing it after an explicit prompt (as a setting, ie auto-update).

Until that happens, though, I don't wish for the death of app stores. Especially, f-droid is a great ecosystem.

Re:Wgpu-rs on the web by Kamshak on Thursday April 23, 2020 @08:33AM (#22955237)
Even though I agree with the benefits of having control over updates seeing how popular SaaS has become I find it quite likely this will happen to (many kinds of) Apps as well.
Re:Wgpu-rs on the web by saagarjha on Thursday April 23, 2020 @04:01PM (#22960504)
Of course, native apps give a lot of control to your platform vendor or application distribution service.
Re:Wgpu-rs on the web by neutronicus on Thursday April 23, 2020 @11:00AM (#22956757)
I don't know.

Rust's most successful UI story appears to be "punt and delegate to JS via Electron, RPC, etc." There might be some client-side wasm Model written in Rust that the JS is calling into, but the making of widgets and whatnot is in JS.

Note that this parallels all the hipster languages of yesteryear, which invariably answered questions about the GUI story with one of "punt and delegate to C via a thin wrapper over WxWidgets or what have you" or "punt and delegate to the browser via some combination of JavaScript and HTTP."

The path for Rust to overtake JS in browser land is something like "compile an already-existing Qt-in-Rust to wasm with some browser-API-specific back end."

But Qt-in-Rust doesn't even exist.

Re:Wgpu-rs on the web by jfkebwjsbx on Thursday April 23, 2020 @12:43PM (#22957896)
Not a chance. There are two main issues: technical and financial.

Technically, Rust is way too complex and therefore expensive to hire for. Same reason why other languages like C++ that compile to Wasm won't succeed either.

Financially, Google and Apple won't allow their digital stores lose market.

But even if those reasons weren’t a thing, Wasm is not as fast as native code and it would be a huge waste of bandwidth downloading every time game resources (measured in gigabytes these days!), even if you cache and allow huge offline storage.

In the end, you end up with a pseudo operating system, but just worse.

Re:Wgpu-rs on the web by pjmlp on Thursday April 23, 2020 @04:31PM (#22960943)
Google is the big pusher for PWAs and WebAssembly, though.
Re:Wgpu-rs on the web by fulafel on Thursday April 23, 2020 @06:23AM (#22954461)
Web scripting trends are pretty hard to predict so who knows. The basic obstacle for this is that Rust is much harder to pick up than other JSVM targeting languages and the "doing without GC in exchange for hard to understand borrow checker" tradeoff isn't really valuable on the web.
Re:Wgpu-rs on the web by satvikpendem on Thursday April 23, 2020 @07:36AM (#22954888)
I can't see a Rust framework becoming one of the top web frameworks simply by virtue that Rust is more complex to learn and implement than Javascript. However, I can see your second point coming true, a fully native framework that eschews the DOM by compiling directly onto a canvas, just as a game compiled with WASM would. The prime example is Flutter Web, which has an experimental WASM renderer that displays onto a canvas. Of course, now they have to reimplement all of the functionality such as scrolling, accessibility and so on. It also somewhat addresses your second point, where you can compile to iOS and Android but also to the web so you can make a Flutter app a progressive web app.
Re:Wgpu-rs on the web by olah_1 on Thursday April 23, 2020 @09:04AM (#22955454)
> a fully native framework that eschews the DOM by compiling directly onto a canvas

Wouldn't that essentially be the death of accessibility on the web, though?

Re:Wgpu-rs on the web by satvikpendem on Thursday April 23, 2020 @10:04AM (#22956077)
I see this concern a lot with Flutter or similar WASM -> canvas frameworks, and I think it's unfounded. Just because it's a canvas doesn't mean there's no accessibility. Indeed, even desktop apps are canvas like in that one cannot view the source and they can render using similar frameworks like Skia, or even Skia itself, yet they still have accessibility.

Flutter's developers have specifically included accessibility settings that devs should use, such as Semantics widgets, just like aria labels for the web. Flutter also constructs a separate semantic DOM like tree that screen readers hook into. So there are both built in things and things that devs can use to make their projects more accessible.

This video shows more about it: https://www.youtube.com/watch?v=bWbBgbmAdQs

https://flutter.dev/docs/development/accessibility-and-local...

https://api.flutter.dev/flutter/widgets/Semantics-class.html

Re:Wgpu-rs on the web by olah_1 on Thursday April 23, 2020 @10:21AM (#22956286)
My comment was less about possibility and more about willingness.

But it looks like many are taking accessibility as a first-class concern, which is great to see.

Re:Wgpu-rs on the web by adev_ on Thursday April 23, 2020 @09:19AM (#22955592)
> Wouldn't that essentially be the death of accessibility on the web, though?

It does. And would condemn us to live again usability nightmare of the flash epoch.

People are confusing two things here: There is no need of replacing the DOM. There is a need to replace (modernize) the API controling the DOM.

Re:Wgpu-rs on the web by pornel on Thursday April 23, 2020 @05:49AM (#22954300)
I wish it was true, and maybe the web would be better off if it happened… but I don't see it happening.

The JS ecosystem is huge and thriving. TypeScript is good enough that there's no burning need to replace it.

Re:Wgpu-rs on the web by twic on Thursday April 23, 2020 @05:22AM (#22954158)
"Top" measured how, and how much would you like to bet?
Re:Wgpu-rs on the web by sullyj3 on Saturday April 25, 2020 @05:07AM (#22976777)
> I'm willing to longbets that by 2025 we see a Rust framework as the top browser toolkit.

I might be willing to take that, depending on the odds and the deciding method for determining the "top browser toolkit".

Re:Wgpu-rs on the web by pjmlp on Thursday April 23, 2020 @08:31AM (#22955221)
Not really, Rust ergonomics aren't yet there for writing GUI code.

Flash like tooling is what will eat JavaScript's lunch.

Unity, Unreal, Blazor, Animate CC, Qt, ...

Re:Wgpu-rs on the web by pcwalton on Thursday April 23, 2020 @12:44PM (#22957910)
Animate CC is Flash. There is no chance Flash is going to "eat JavaScript's lunch" in 2020.
Re:Wgpu-rs on the web by pjmlp on Thursday April 23, 2020 @04:02PM (#22960506)
It all depends in how committed you are into making browsers general purpose VMs via WebAssembly.
Re:Wgpu-rs on the web by flohofwoe on Thursday April 23, 2020 @07:03AM (#22954661)
TBH, I doubt it, writing "high level" Rust requires a too big "runtime portion" (in the same sense of "runtime" as the stdlib in C++, which also tends to bloat up executables), while "embedded style" minimal Rust without such a "runtime part" is so low-level you could just as well write C code (which is also "memory safe" in that environment because of WASM).

And even in the best case, a WASM blob still has a hard time beating a bit of Javascript if it is just used to glue a couple of browser APIs together (and in such a situation, the good or bad qualities of that "glue language" don't matter much).

Hybrid JS/WASM applications make a lot more sense, where some small performance-critical parts are implemented in WASM in a "runtime-free language", glued together by Javascript (similar to how python is often used as glue between functionality implemented in native DLLs).

Re:Wgpu-rs on the web by chrismorgan on Thursday April 23, 2020 @07:16AM (#22954739)
Are you in the habit of using Rust + WASM? From how you’re wording this, I suspect not. Rust really doesn’t require a large runtime (until you do something that requires Unicode tables, then you pay a certain tax), and the difference between high-level and embedded styles is normally small to nothing—the whole concept of zero-cost abstractions is normally talking about performance, but correlates extremely strongly with code size too; such abstraction layers typically compile out of existence.

Also there’s still a fairly big difference between a more frugal style of Rust and C. Just because it can’t cause arbitrary code execution and the likes doesn’t make C safe to use.

Yes, when developing for the web people will hopefully pay a little more attention to binary size, because WASM does have a tendency to make big code blobs easier to produce, especially if you’re using generics liberally.

Finally, although at present the browser WASM story requires it to interact with the browser through JavaScript, that limitation is planned to be removed.

Re:Wgpu-rs on the web by flohofwoe on Thursday April 23, 2020 @10:15AM (#22956200)
I have admittedly not much experience with Rust+WASM (I dabbled in Rust though), but enough with C and C++ on top of WASM, and the situtation is really quite similar to C++ (IMHO of course).

Theoretically, C++ also has no "runtime overhead", but start using high-level stdlib features, and suddenly there is a non-negligible overhead. It's possible to cut that down, but that requires a lot of "insider knowledge" of the compiler toolchain and the specific stdlib implementation. In the end it's always about deciding what C++ features to not use to cut the size down, and at the end of that process is a language that's essentially C (no generic containers, no automatically managed memory etc).

And even when using C it is non-trivial to cut down the overhead from the C runtime library functions so that it becomes "competitive" with minified Javascript doing the same thing.

Don't get me wrong, Rust's toolchain integration with WASM is excellent. But I wouldn't call Rust compiled to WASM a contender for killing Javascript.

Re:Wgpu-rs on the web by brabel on Thursday April 23, 2020 @11:33AM (#22957109)
> because WASM does have a tendency to make big code blobs easier to produce, especially if you’re using generics liberally.

WASM was designed to be compiled to very small binaries. The big code blobs you see are produced by the Rust compiler and are not a characteristic of WASM... just check the output of the Rust compiler for a hello world project in WAT format and you'll see it consists almost entirely of the memory allocator that's included in the binary...if you write the same code in WAT directly, or something like AssemblyScript[1], which is designed to use WASM primitives, it's going to be a few bytes for your typical WASM hello world.

[1] https://docs.assemblyscript.org/

Re:Wgpu-rs on the web by chrismorgan on Thursday April 23, 2020 @01:21PM (#22958365)
I’m not talking about the constant overheads, but how WASM grows as you scale your code base. My experience is that in practice it tends to be grow a little faster than equivalent JavaScript, say 1.2–2× the size depending on what you’re doing. But I should definitely have clarified that I was speaking specifically in the context of Rust—my generics remark certainly only makes sense in that context.

It’s not fundamentally terribly much larger, and can definitely be smaller (again, depending on what you’re doing), but using it as a compilation target makes it much easier to produce binaries larger than you anticipated. In JavaScript you distribute what you wrote, so you know if you loaded a lot more code. Well, in theory. Code bundlers and liberal importing of third-party libraries kinda put paid to that.

Re:Wgpu-rs on the web by pjmlp on Thursday April 23, 2020 @08:16AM (#22955111)
Not really, because WASM doesn't do bounds checking on linear memory access, while Rust, C++ (with STL data types) do it.
Re:Wgpu-rs on the web by flohofwoe on Thursday April 23, 2020 @10:07AM (#22956118)
WASM provides enough memory safety so that memory corruption errors in the WASM heap can't be used to escape the sandbox (assuming there's no exploitable bug in the sandbox itself of course). It doesn't protect from memory corruption inside the WASM heap of course.
Re:Wgpu-rs on the web by pjmlp on Thursday April 23, 2020 @11:10AM (#22956872)
A fun exercise would be compiling the Heartbleed version of OpenSSL into WASM.

Exploits can escape the sandbox, via functions exported from WASM that change their behaviour due to internal memory corruption, or callbacks that get called with unexpected parameters from the WASM code due to the internal memory corruption that changed the execution logic.

For example, a security system that would grant higher credentials than it was supposed to.

Re:Wgpu-rs on the web by postalrat on Thursday April 23, 2020 @10:54PM (#22964181)
I'm no expert but I believe in wasm memory and code are separate.
Re:Wgpu-rs on the web by pjmlp on Friday April 24, 2020 @03:13AM (#22965446)
Yes it follows Harvard architecture, still you can produce exploits by corrupting memory, no need to rewrite code, it just becomes harder to achieve them.

Basically by corrupting memory, you can achieve that the executing path changes and what was false is now true, thus influencing the outcome of what gets called and their parameters, without having to change any byte of the code.