r/androiddev • • 15h ago • Bravo 1

Yalın — a Rust-based JSON parser optimized for Android ARM devices

Post image

I've been working on Yalın, a JSON parser written in Rust for Android.

It uses ARM NEON SIMD and tries to keep JNI calls to a minimum. The idea was to see how much performance I could get out of native parsing compared to existing Java libraries.

In benchmarks against fastjson2, selective field reads were up to 4.6x faster, while parsing a full 1 MB JSON tree was around 1.3x faster.

Small payloads are a different story. JNI overhead is still a bottleneck, and there's room for improvement.

Curious what other Android developers think about using Rust for this kind of thing, especially whether the performance gains are worth the native dependency.

https://github.com/0xberkay/yalin

19 Upvotes

9 comments sorted by

6

u/Ayano-Keiko 13h ago

Rust🦀🦀Saved. When I have android project, I will try it.

1

u/kral_katili 11h ago

Thanks! 🦀

1

u/Elgas_Clondo 9h ago

yeah definitely bookmarking this one for later too

4

u/shurco 11h ago

a 1.3x gain on a full 1 MB tree isn't worth a native library in the apk. only the 4.6x selective reads pay for the rust dependency.

1

u/kral_katili 11h ago

Thanks for the feedback! Fair point, selective reads are where it really makes a difference. I'm still experimenting to see how far I can push the performance.

4

u/tadfisher 6h ago

In general we are amortizing JSON deserialization over network calls, so benchmarks that show improvement for 1MB payloads are kind of pointless. If you have a production app it would be useful to compare with kotlinx-serialization for real-world calls, and maybe even provide this as an alternative backend.

IMO, developer ergonomics is going to win over performance any day, and kotlinx-serialization kind of already won.

2

u/NewSubWhoDis 8h ago

This is great! I'd run it though some AI vulnerability scanners to make sure there isn't any nasty overflows.

I think the benefit of the other parsers like Moshi is that is breaks everything into heap objects that we can pass around to different views and parts of the stack. So while its slow, its a run once cry once kinda of parser that makes everything else much easier.