frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

Lessons from Mixing Rust and Java: Fast, Safe, and Practical

https://medium.com/@greptime/how-to-supercharge-your-java-project-with-rust-a-practical-guide-to-jni-integration-with-a-86f60e9708b8
65•killme2008•3d ago

Comments

lukax•5h ago
Do not write the bindings manually. Just use the amazing uniffi-rs library from Mozilla.

https://github.com/mozilla/uniffi-rs

You can generate bindings for multiple languages. It supports error handling on both sides and latest versions also support native async integration.

I've used it to reuse the same Rust engine in iOS and Android apps and write native UI.

https://github.com/koofr/vault

cadamsdotcom•4h ago
Thanks! Anywhere you hit issues?
invalidname•4h ago
Why didn't OP use Panama or the modern Java native APIs which are far better than JNI?
cyberax•4h ago
Android?
invalidname•4h ago
Does OP target Android?
pjmlp•3h ago
Proving the point about Android being Google's J++, and Kotlin their C#.
sgt•3h ago
Should be possible with Zig as well. Is this one up to date? https://github.com/zig-java/jui
rusbus•2h ago
Another useful library in this space that allows you to avoid manually writing bindings is https://github.com/duchess-rs/duchess
never_inline•2h ago
1. The article seems kind-of shallow. I didn't see any concrete (qualitative or quantitative) remarks about the "fast" part. I don't doubt you have reasons to do this - but I expected some information on what component are you writing using Rust + JNI, and how it helped? Or is it just a demo?

At some point, repeated calls into the JNI are counter-productive to performance, since the JIT can not optimize them. Pinning affecting garbage collection is another potential drawback if any of your rust calls are long lived. If we don't measure and just conclude "we are fast because rust is faster than Java, and we took average of both speeds", it's a disservice.

2. Also, I see unsafe for each call? I'd rather isolate this into a class / different file, since in JNI only few types of calls are possible. (method returning one of the primtive types, an object or `void`). This is the approach I took in dart jnigen. (Though there, the call is Dart -> Java, not Java -> Native language).

    unsafe {
      env.call_method_unchecked(
                java_logger,
                logger_method,
                ReturnType::Primitive(Primitive::Void),
                &[JValue::from(format_msg(record)).as_jni()]
      );
    }
3. I believe some details are missing here. What's native_add_one mapped to? And how is tokio futures awaited from Java? I believe that's the important part you should be presenting.

    public CompletableFuture<Integer> add_one(int x) {
        long futureId = native_add_one(x); // Call Rust
        return AsyncRegistry.take(futureId); // Get CompletableFuture
    }
4. Also please don't use ChatGPT for writing anything. It totally derails the reader by mentioning irrelevant details and long winded corporate conclusion at the end of every sentence.
killme2008•1h ago
This article summarizes our experience from a commercial project that runs on an in-vehicle Android system. In this project, we needed to invoke Rust code(DB) from Java(App), so we couldn't directly use the project’s source code for demonstration. Instead, we created a demo project: https://github.com/GreptimeTeam/rust-java-demo

1. I agree that using Rust doesn't necessarily mean faster performance; it simply gives you the opportunity to implement some compute-intensive modules in Rust, which is a possible approach.

2. This is a great suggestion, and we organized our project in the same way. You don’t need to use unsafe for every call. However, if you want to call JNI APIs from Rust, unsafe is required.

3. Sorry, some details were missing here. We use AsyncRegistry(Java) as an intermediary. Before initiating an async operation in Rust, we need to call Java code in advance to register a future and obtain a unique future ID. After the async execution completes, we retrieve the registered future by its ID, and then complete it or complete it exceptionally depending on the async result. You can refer to this code: https://github.com/GreptimeTeam/rust-java-demo/blob/90ffa0ba... and https://github.com/GreptimeTeam/rust-java-demo/blob/90ffa0ba...

4. This article was not generated by AI; it’s just that our official blog has a fixed template at the end. Sorry for the inconvenience.

bullen•1h ago
I agree that Java + native is the way to go.

But does rust really give you an edge over C/C++?

Here is how you do JNI with C++: http://move.rupy.se/file/jvm.txt

So simple it's ridiculous!

Then you can use RegisterNatives to give C++ API to the Java side instead of the stub (Java calls C++ .dll/.so) thing...

Spaced repetition systems have gotten way better

https://domenic.me/fsrs/
41•domenicd•51m ago•3 comments

Thank you Google for breaking my YouTube addiction

https://rakhim.exotext.com/thank-you-google-for-breaking-my-youtube-addiction
68•ambigious7777•38m ago•37 comments

AniSora: Open-source anime video generation model

https://komiko.app/video/AniSora
259•PaulineGar•12h ago•103 comments

Coding without a laptop: Two weeks with AR glasses and Linux on Android

https://holdtherobot.com/blog/2025/05/11/linux-on-android-with-ar-glasses/
744•mikenew•3d ago•286 comments

Lessons from Mixing Rust and Java: Fast, Safe, and Practical

https://medium.com/@greptime/how-to-supercharge-your-java-project-with-rust-a-practical-guide-to-jni-integration-with-a-86f60e9708b8
65•killme2008•3d ago•11 comments

Show HN: Turn any workflow diagram into compilable, running and stateful code

https://workflows.diagrid.io/
66•yaronsc•3d ago•13 comments

Experts have it easy (2024)

https://boydkane.com/essays/experts
112•veqq•11h ago•36 comments

Mystical

https://suberic.net/~dmm/projects/mystical/README.html
274•mmphosis•18h ago•34 comments

Project Verona: Fearless Concurrency for Python

https://microsoft.github.io/verona/pyrona.html
95•ptx•3d ago•54 comments

Pglocks.org

https://pglocks.org/
72•hnasr•9h ago•10 comments

What Every Programmer Should Know About Enumerative Combinatorics

https://leetarxiv.substack.com/p/counting-integer-compositions
30•muragekibicho•3d ago•15 comments

Directory of MCP Servers

https://github.com/chatmcp/mcpso
175•saikatsg•17h ago•59 comments

Push Ifs Up and Fors Down

https://matklad.github.io/2023/11/15/push-ifs-up-and-fors-down.html
494•goranmoomin•1d ago•177 comments

ARMv9 Architecture Helps Lift Arm to New Financial Heights

https://www.nextplatform.com/2025/05/12/armv9-architecture-helps-lift-arm-to-new-financial-heights/
85•rbanffy•4d ago•40 comments

How to have the browser pick a contrasting color in CSS

https://webkit.org/blog/16929/contrast-color/
207•Kerrick•20h ago•65 comments

If nothing is curated, how do we find things

https://tadaima.bearblog.dev/if-nothing-is-curated-how-do-we-find-things/
251•nivethan•20h ago•183 comments

Dead Stars Don’t Radiate

https://johncarlosbaez.wordpress.com/2025/05/17/dead-stars-dont-radiate-and-shrink/
215•thechao•18h ago•109 comments

Show HN: Pixelagent – Build your Stateful Agent Framework in 200 lines of code

https://github.com/pixeltable/pixelagent
19•pierrebrunelle•2d ago•7 comments

Palette lighting tricks on the Nintendo 64

https://30fps.net/pages/palette-lighting-tricks-n64/
200•ibobev•22h ago•46 comments

Mice grow bigger brains when given this stretch of human DNA

https://www.nature.com/articles/d41586-025-01515-z
46•pavel_lishin•3d ago•24 comments

Understanding Transformers via N-gram Statistics

https://arxiv.org/abs/2407.12034
92•pona-a•16h ago•7 comments

Mexican Navy ship crashes into Brooklyn Bridge leaving two people dead

https://www.theguardian.com/us-news/2025/may/18/mexican-navy-ship-hits-brooklyn-bridge-during-promotional-tour
88•teleforce•6h ago•47 comments

O2 VoLTE: locating any customer with a phone call

https://mastdatabase.co.uk/blog/2025/05/o2-expose-customer-location-call-4g/
281•kragniz•23h ago•58 comments

Memetics – A Growth Industry in US Military Operations (2006) [pdf]

https://apps.dtic.mil/sti/pdfs/ADA507172.pdf
43•lawrenceyan•11h ago•15 comments

Climbing trees 1: what are decision trees?

https://mathpn.com/posts/climbing-trees-1/
29•SchwKatze•9h ago•1 comments

Espanso – Cross-Platform Text Expander Written in Rust

https://github.com/espanso/espanso
100•kartikarti•3d ago•25 comments

Bike-mounted sensor could boost the mapping of safe cycling routes

https://newatlas.com/bicycles/proxicycle-bicycle-sensor-safe-cycling-routes/
82•yunusabd•4d ago•43 comments

FreeBASIC is a free/open source BASIC compiler for Windows DOS and Linux

https://freebasic.net/
99•90s_dev•13h ago•32 comments

Pyrefly: A new type checker and IDE experience for Python

https://engineering.fb.com/2025/05/15/developer-tools/introducing-pyrefly-a-new-type-checker-and-ide-experience-for-python/
210•homarp•23h ago•131 comments

Internet Phone Book

https://internetphonebook.net
18•surprisetalk•2d ago•1 comments