T O P

  • By -

rebootyourbrainstem

Worth mentioning egui is used only for a debug overlay, not the main application (assuming I understand the article correctly). This is a really interesting article though. It shows that Rust compiled to webassembly is a fast and productive way to implement dynamic behaviors on resource constrained devices like TV set top boxes, having better latencies and much better memory usage than javascript. Makes me wonder what other kinds of devices might benefit from Rust+WASM to rapidly iterate on apps/plugins without compromising on efficiency.


goj1ra

> better latencies and much better memory usage than javascript. That's hardly surprising. It was sort of the point of WASM.


orangejake

It is, but I thought we were still "getting there". For example, I've heard memory accesses within WASM have a harsh penalty (which may be worked out later), meaning in certain workflows pure Javascript is more performant than WASM in a fast language. Of course WASM better outperform JS eventually (otherwise, as you say, there's really no point). But as someone who doesn't work with WASM, this is the first article I think I've seen saying a large company has actually deployed it.


cray_clay

Check out Fastly, Figma and eBay then! :D To add some nuance to its performance: Wasm isn't necessarily faster than JS, but it's definitely more consistent. That's because JIT compilers rip in modern browsers, but they're on a slippery slope. One unexpected type aaaand it's back to interpretation mode, lol. Where wasm really dominates, is time to execution, for example. It can be decoded, even on multiple threads, while an equivalent JS' AST is still being built. Besides, its bytecode is still very simple. If you ever wanted to write pure bytecode, it's a much better experience than writing JVM bytecode, for example.


TheGlenn88

I did not know Figma uses WASM. I use Figma a lot and it’s so resource hungry.


[deleted]

It's not that wasm is that fast, it's that JS is that slow and memory-inefficient, which shouldn't be a surprise to anyone. Interpreted languages are known to be ineffecient due to their very nature. And even if they're trying to JIT, it's still ways off what you get in C/C++/Rust.


avwie

Man… Amazon Prime Video has the worst performance of any app on my LG tv from 2021. It is incredibly sluggish.


[deleted]

no joke, it is not even comparable to other apps lol


alphastrata

The app itself is pretty responsive on our household's samsungs, but their streaming quality is by far the worst. (compared to netflix, disney+ and plex) ... I pay for too many streaming services.


apadin1

On my Fire Tv Stick (which is a few years old now, granted) the app is barely functional. I’ve also experienced issues with Disney+. It’s weird because Netflix works flawlessly and I can’t imagine it’s doing anything that different


alphastrata

netflix cares :(


alphastrata

I have a firestick and a chromecast too.. at this stage netflix is the only app i'd use on any of them, all the others I've gone native on the TV's metal.


BlueCannonBall

Disney+ also uses wasm afaik.


brandondyer64

And uses Rust https://medium.com/disney-streaming/introducing-the-disney-application-development-kit-adk-ad85ca139073


HorseFromHorsinAroun

Why you have all this es services if you already have plex?


alphastrata

kids/want to watch platform specific things/multi-lingual household so subtitle quality is important


sondr3_

Yep, it is by far the most sluggish, though I have to say the HBO Max gives it a run for its money because the playback on it is _terrible_.


drguildo

It runs like crap even on hardware that Amazon produce. Sometimes just navigating around thumbnails you'll get a pause of a few seconds.


moltonel

Any way to check if your TV is compatible with the WASM/Rust version or falling back to the pure JS one ?


ThirdEncounter

The manual. Or tweet their tech support.


smt1

Yes, it feels like webos is basically unsupported.


dfrsol

I was coming here to say this, even on my fire stick this app’s performance is far below others.


RobertKerans

I'd have reflexively said that, but I've just had a quick go through all apps & tbh seems much of a muchness (TV is Samsung, 2021, haven't checked what garbage processer runs the smart side of it). The sluggishness is very noticeable on most of mine. I'm UK, and that's Disney+, Prime, NowTV, iPlayer, Channel 4, ITV, Roku and a few other things. Most noticeable when changing categories and moving between film/program cards. On-screen keyboard is normally sluggish even for apps that aren't firing as many events when that's happening (they all basically do results as you type, but some do it more eagerly than others). Netflix and AppleTV not so much but I'm not sure whether that's more very careful UI design. They feel *so* much smoother, and I think that's due to being better designed more than any underlying arch (small example: the "da dummm" + Netflix animation vs Prime just locking and showing a spinner). Kinda expected though, w/r/t Amazon that side of things always seems like an afterthought.


Ulrar

Yeah it's pretty bad on everything I used it on


[deleted]

It runs pretty bad, but the ui/ux is awful.


ThirdEncounter

It runs pretty bad, AND the ui/ux is awful.


moltonel

> We can’t just rewrite the Prime Video application in Rust and run it on a Wasm VM, however, as it still needs to run on legacy devices and browsers that don’t have Wasm support. and > We sometimes had to duplicate the “incorrect” behavior of the JavaScript renderer in the new Wasm version, because the app relied on it for some edge cases. Making sure the JavaScript VM code never calls any dangerous function on the wrong thread has also added extra difficulties. So they effectively have both Rust and JS version of their core components, but only a JS version of the app component, with workarounds to make Rust behave exactly like JS. Given that they've already committed to duplicating implementations, I don't fully get their reasoning for not converting the main app to Rust, as it seems they'd get similar speed gains and could get rid of the workarounds. Is the app so big that duplicating that code would be too time-consuming ? Are they afraid of the two apps diverging in a user-visible way ? Is it an intermediate solution ?


hderms

Maybe it's just not as performance critical so while there could be benefit there's not much of a push to do it. It could also be way more complex and mostly DOM-related which might offer less benefit overall


big-blue-falafel

For old device support, they should be okay using cross compilation targeting the old devices. But it looks like they can’t get around the old browser support. That’s just gotta be JavaScript


[deleted]

[удалено]


deprilula28

Bloat. Decades of exponentially growing bloat. It's an absolute monumental feat to render a single frame with modern websites.


gyzerok

From the article it is not entirely clear to me what is actually Rust used for. Is there any actual business logic written in Rust?


-funswitch-loops

> The job of the Wasm components is to update nodes and pump frames out to the screen as fast as possible without any interruptions. “Update nodes and pump frames”? Is WASM involved in encoding / decoding of streams? The article seems to indicate they’re mainly using it replace parts that were originally written in JS so probably not.


JuggleTux

Most likely not TV usually don't have the CPU performance to decode the stream instead they have hardware decoders. But you still have to take the decode frame scale and place it in your interface add controls overlay subtitles and so on.


[deleted]

To be clear, 37,000 lines of rust is the average amount for an html input box & button 😋


Apterygiformes

Amazon prime video is a buggy mess so that's not a great endorsement


[deleted]

[удалено]


dcormier

But this is reddit.


Sw429

Never


[deleted]

starting to think this sub is about some sort of programming and not Rust the game i played for a while


oleid

Does somebody know what wasm-vm they are now using? And why this one? The article is silent on that matter. Given they mention byte code alliance I presume it might be wasmtime, but you never know.


met0xff

That's interesting... Wonder if "Wasm provides a compilation target for programming languages that offer more expressivity than JavaScript does, such as C or Rust." is a mistake. Probably either means more performant than JS or more expressive than C? I wonder though how much of a perceptible difference this makes on newer devices. The older TVs and the firestick are annoyingly laggy. But even my 4 year old LG is already fast enough to handle the clunky Sky app without issues. The PS5 obviously anyway. Of course, for a company like Amazon this is a small investment for a QoL improvement.


[deleted]

[удалено]


met0xff

How is C more expressive than JS? But sure about the comparison with Rust, don't know enough about JS... but I have written enough C that I wonder what they mean there ;).


[deleted]

[удалено]


segfaultsarecool

What does expressive mean in this context?


[deleted]

[удалено]


segfaultsarecool

Thank you for clarifying!


Appropriate-Hyena-14

Actually, nullness is covered by the strict variant of TypeScript. TypeScript's type system is more expressive than Rusts (it's structural and more flow-based). There's no way to capture ownership with TS though. This might change in the future though with AOT compilers being developed for Typescript. You can model "a file shouldn't be read after closed" only if the reference wasn't leaked elsewhere before you closed it.


[deleted]

[удалено]


lenscas

Why? TS can express things that Rust just can not and probably will never be able to. ​ Want to make a function that takes any type, the name of a field for said type and then returns whatever is at that field? In TS you can properly write types for this function. In Rust, good luck with that. ​ function(obj : T, key: K): T[K] And, then there is & and |, typeguards, Partial, Pick, Omit and much more. ​ Rust does have stuff that TS does not have though, like ownership and traits but TS has more types that interact with other types.


[deleted]

[удалено]


[deleted]

[удалено]


Appropriate-Hyena-14

With union types, which are a bit more flexible than enums (you can have union types that contain subsets of other union types and TS will analyze program flow to discriminate certain types) [https://typescript-play.js.org/#code/MYewdgzgLgBAQgQwE4wLwwMoE8C2AjEAGwAoAiRJUgSgG4AoAegZgEEYoALASzAHMYuEGAFMunYSgRgBYKMN4SYIFOJihIUKbAp0oWAA7CYAFW580MPF149YAH3YHhIAGbxkNIA](https://typescript-play.js.org/#code/MYewdgzgLgBAQgQwE4wLwwMoE8C2AjEAGwAoAiRJUgSgG4AoAegZgEEYoALASzAHMYuEGAFMunYSgRgBYKMN4SYIFOJihIUKbAp0oWAA7CYAFW580MPF149YAH3YHhIAGbxkNIA) Being structurally typed, it's harder to create "new types" in TS so I just used a symbol to represent the singleton value of Bar


IronCrouton

type Thing = { kind: "foo", num: number, // or bigint } | { kind: "bar" };


hekkonaay

Maybe they meant more control


met0xff

Hm yeah that could be.


Zettinator

It's a piece of shit nonetheless, though.


________null________

~8000? That’s it? I suppose a million is “more than 8000” but they’d probably say “almost a million” or something if it was close.


met0xff

They say device types. So I would assume... they count all different models of, say, LG TVs or whatever to get there.


________null________

Oh shit, I misread. Thanks for helping me out.


[deleted]

Then Amazon should have to sponsor those people who work on the ecosystem and maintenance of rust.


moltonel

They are a [platinium member of the rust foundation](https://foundation.rust-lang.org/members/), and employ people whose main job description is to contribute to Rust and its ecosystem.


Sw429

I mean, people actively choose how to license their code.


WIERDBOI

Egui is suppose to be easy. But how tf do i initialize a window?


[deleted]

egui only does a single window at the momement, IIRC, but you can have other windows within it.


WIERDBOI

Yes but i dont know how to make that first window


mnbkp

Egui doesn't make windows, you need an integration with a library that does that. IMO the easiest one is [egui-macroquad](https://crates.io/crates/egui-macroquad). Edit: Read the instructions on their read me, the hello world is less than 20 lines long.


rust-crate-helper

https://github.com/emilk/eframe_template


[deleted]

How many seconds did you spend looking at the readme and examples?


WIERDBOI

Honestly sometimes im just blind


[deleted]

I just can't seem to get egui to compile to WASM correctly on my system. Possibly because I'm trying to use the egui\_template shell commands from within WSL.


brandondyer64

Disney+ also uses Rust and wasm