Immediately after switching the page, it will work with CSR.
Please reload your browser to see how it works.

Source:https://github.com/SoraKumo001/next-streaming

⬅️ Lessons from Mixing Rust and Java: Fast, Safe, and Practical
lukax 7 hoursReload
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


never_inline 4 hoursReload
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.

aeonik 47 minutesReload
I thought JNI was being deprecated in favor of the new FFM interface.

https://openjdk.org/jeps/472


koakuma-chan 21 minutesReload
I found mixing Bun and Rust works pretty well. Bun has gotten many cool new things recently which feel great to use and it has a nice FFI API. So I have Next.js apps running in Bun runtime and anything CPU bound is written in Rust and called via FFI.

rusbus 4 hoursReload
Another useful library in this space that allows you to avoid manually writing bindings is https://github.com/duchess-rs/duchess