#Rust vs JS Performance in Tauri App

6 messages · Page 1 of 1 (latest)

willow gust
#

Is there a performance benefit when using Rust rather than JS in your Tauri app? Would Rust calculating something and sending it to JS to use be faster than JS calculating it? I'd assume Rust, but I'm not sure if the communication between Rust and JS comes with slight performance downsides.

Ex: Rust does 1+1 and gets 2, then sends to JS. JS does 1+1 and gets 2. Would the 2 sent by Rust have been made available to JS faster than if it had calculated a 2 itself?

hollow widget
#

if is small data with heavy calculation, then probably rust is using half the time that js would(data is nodejs, not browser) or faster
if is large amount data with lite calculation, then probably just do it in js is better

#

it's really depend on what data need to be transfer and what calculation need to be done.

vestal vortex
#

best way to determine performance is by measuring it. A lot of processing would have to happen for it to be noticeably faster in Rust. It can be many times faster in rust, but if processing takes 30ms in JS instead of 5ms in Rust, that's not noticeable

#

so yeah, definitely what Golden_Water said, it really depends. Write the logic where it's easier for you, and if it gets noticeably slow, start optimizing then

solemn steeple
#

Depends on the calculation you need to do

In general the best way to avoid IPC is by keeping as much as possible in the Rust end instead of the frontend. Then you can perform smaller operations without the IPC being an issue

Lots of people put their logic in JS however, so the IPC becomes a major factor

So in general, for 1 + 1, the IPC overhead results in Rust being slower. BUT, Rust is always (sometimes literally) a million times faster than js

If you have something that takes >1 second to perform in JS, usually you can cut that time down using Rust

If you have lots of data in JS, or if the comoutation returns a lot of data, usually the IPC will have overhead that makes it slower

If the input is small but the output is large, there are streaming techniques you can use from Rust to JS to avoid the slowness of the IPC

Also you should consider that you can create a WASM library for your frontend as well and still benefit from Rust being faster without the slowness of the Tauri IPC. Tauri Rust is faster than WASM Rust, but if you need something faster than WASM Rust you're probably doing something horribly wrong and need to optimise the function, not just throw a bad function into a faster language. Bad code is bad code, 10000 * 10000 is fast, looping 10000 times and incrementing an integer is slow, think about code quality, usually you shouldn't even need something faster than JS honestly if the code is well written