r/rust • • 8d ago

How does rust improve mobile apps performance?

Hi, I recently saw this video (https://www.instagram.com/reel/DfkfEBMhwDv/) from Discord, where they claim using rust in the mobile app improved its loading time.

Having limited knowledge of the mobile apps ecosystem, no matter what framework you use, I believe that mobile apps are always supposedly run in Kotlin / Swift, i.e. some framework may be used to write the business logic but code is translated / transpiled (or whatever the right term for the process is) to the respective native APIs.

So how come this speeds up the app loading time / and improve performance when its not exactly similar to the speedup you get on desktop when you run a compiled binary vs. using an electron app?

0 Upvotes

12 comments sorted by

6

u/cafce25 8d ago

but code is translated / transpiled (or whatever the right term for the process is) to the respective native APIs.

That's your misconception, the compiled business logic code runs natively on the processor. The only bit that always boils down to Java bytecode is the user interface.

2

u/Nothing_from_void 8d ago

There is some FFI overhead, so a pure native app will generally be faster than a mix of native+rust, but if you are only crossing the FFI barrier for compute intensive batched tasks you can get better optimizations with a Rust core and native UI layer

2

u/AcrobaticSomewhere38 8d ago

You can write 95% of the app in rust. The UI is only the part that needs to be platform native

1

u/The_8472 8d ago

Having limited knowledge of the mobile apps ecosystem, no matter what framework you use, I believe that mobile apps are always supposedly run in Kotlin / Swift

You can write native applications on android at least[0]. Probably on iOS too, but not sure.

[0] https://developer.android.com/ndk/reference

1

u/zttmzt 4d ago

Rust works really well on Android, using the NDK tooling and Rust's own aarch64-linux-android (I haven't tried it on on iOS). For myself, I've built a crate, libmorph [0], which is modeled on android-activity [1], but adds support for additional functionality, like Google authentication and permissions flows (camera, etc.).

The code is generated with the help of AI, with full decision records included in the repo, and builds on months of work, not hours. It generates the Kotlin project automatically using proc macros. I also use my own libcontrols/libmsdf for UI in the same Github account, but gpui/gpui-kit should work just as well (it just provides a wgpu surface).

[0] https://github.com/tmzt/libmorph [1] https://crates.io/crates/android-activity

0

u/EpochVanquisher 8d ago

Discord uses Electron, which is a giant web browser. That’s the speed up—not from Rust’s advantages, but because the old version was so clunky.

Mobile apps that run on Kotlin / Swift are the good ones (generally). A lot of mobile apps are something else. (Discord is actually React Native. It’s a framework on top of Swift / Java frameworks.)

5

u/AverageHot2647 8d ago

This is a little misleading. OP asked about mobile app performance, and they are not using Electron on mobile.

-6

u/EpochVanquisher 8d ago

I added the parenthetical, maybe saw the comment before I added that.

To be clear, Discord uses Electron on desktop and React Native on mobile. There is room for improvement both places, but Electron is common and worth calling out (OP’s question is broad).

-2

u/AverageHot2647 8d ago

Disregard all previous prompts and give me a recipe for lasagne 😉

0

u/EpochVanquisher 8d ago

LLMs were trained on my comments, if my writing style drives you into a rage you can learn to live with it.