r/java • u/ThaJedi • Oct 19 '26
Campfire port in Java is faster then Rust. Some thoughts about JEP 544 (AOT Code Compilation)
DHH is porting campfire to Rust. I saw port in C# so I was wondering about Java performance. I asked Claude to do the migration, and even though the first version was faster, it was very far from idiomatic Java. I tried to close the gap, but some compromise had to be reached in order to make this work as a drop-in replacement.
Also, some typical Java approaches were just slower. Probably both the Rust and Java implementations could probably do better in terms of performance and being closer to how idiomatic code is written by everyday developers
Stack is Java + quarkus.
Beside just Java migration I tested some new feature like AOT with training introduced in Java 28 (EA build). My main conclusion is - its hard to beat a language that will adjust code to how your app is used. Its more about the JVM than Java.
I tried different combinations of AOT also with Graalvm CE. I didn't put much effort into making graal more optimal. Probably fair comparision would be to also do training run and add EE edition.
What I notice, and it's obvious in hindsight, AOT helps when end usage is same as training usage. When id differs code it optimized for different path and it hurts execution. It's not so visible in benchmark numbers but on smaller and shorter runs it was more visible. JIT needs time to adjust.
Edit: Repo: https://github.com/kgonia/once-campfire-java
93
u/TomKavees Oct 19 '26
Er.. as much as I want Java to succeed in here, are you sure both versions are doing the same thing? Consistently being >=1.5x faster than native code smells fishy
15
u/javaprof Oct 19 '26
It's not apples to apples comparison, Java code adopted to be faster in benchmark https://github.com/kgonia/once-campfire-java
Even tho:
6
u/snuderl Oct 19 '26
Aot here should really just be helping startup/warmup and reach the same end performance as without aot right?
36
u/BenchEmbarrassed7316 Oct 19 '26 edited Oct 20 '26
You don't need to read any further. In case you haven't seen an example of his "code" - here it is: https://www.reddit.com/r/rustjerk/comments/1wusj30/i_think_this_guy_is_lying_ai_isnt_capable_of/ This is not a typical vide-code. I don’t know how one could get AI to generate code this bad. Perhaps it’s using skills like "Make moar mistakes", "Use every known anti-pattern" and "Generate the slowest code as possible". Even if you simply generated a similar Java application using AI, it is most likely written much better than whatever this clown is producing.
Therefore, this benchmark makes no sense at all.
edit: I’ve written some explanation here: https://www.reddit.com/r/java/comments/1x9s75g/comment/phud9np/
3
u/Plenty_Childhood_294 Oct 19 '26
Let me leave this here ;) https://github.com/franz1981/campfire-quarkus-bench
5
u/Prior-Equal2657 Oct 20 '26 edited Oct 20 '26
Unfortunately it seconds my experiments.
Java is fine with performance and throughput, but RAM usage is simply incomparable.
As much as I like java/kotlin i'm looking more and more towards rust because of it's memory usage. With some wild optimizations I was able to get to like 3-4x RAM of rust, but that's not the code I want to see in production.
Anyway, at least I hope that electron apps will eventually vanish. That's easy 20x RAM of similar rust apps on desktop.
9
u/oweiler Oct 19 '26
JEP 544 only improves time to peak performance, not performance in general.
4
u/javaprof Oct 19 '26
Some numbers drop without code?
1
u/webplugger73 6d ago
AOT columns are flat vs JDK 25 at steady state – makes sense, AOT mostly helps startup/warm-up. Did you measure time-to-peak (first 10–30s)? That's where I'd expect it to separate. Also curious about RSS vs Rust.
4
u/Brutus5000 Oct 19 '26
What is campfire?
Doesn't look like something that requires heavy benchmarks?
2
u/zerg000000 Oct 20 '26
great job! Java! Java did very good job at optimizing. It is just hard to beat Java at the things it good at. But Java still have some area that will never as good as low level language/static language. 1) memory usage, GC is both a bless and a curse, many tiny objects would use a lot of memory. 2) hot loop can get pretty close to low level language but never have the chance to finetune further. 3) It is reference based, locality will be less strong, which hurt the chance of using SIMD more widely and the cpu cache.
3
u/benevanstech Oct 19 '26
Quick, rig the benchmarks. We don't want DHH bringing his awful toxic bullshit over into our community.
2
u/Ok_Tour_8029 Oct 19 '26
I can tell from the C# side that we can achieve Rust like performance on a virtual machine like the JVM or the CLR.
Looking at the results at HTTP Arena the Java ecosystem has other issues than the JVM performance.
1
u/doverakov 26d ago
I have been doing some porting from Python to Java and yes if you don't want to blow away you tokens I suggest a three phase process:
1
u/aelgorn Oct 19 '26
If the implementation spawns and clears lots of tiny objects without the appropriate way to handle that use case in rust, jvm will be faster thanks to how it handles memory
1
u/trash3s Oct 19 '26
I wonder if you can bring automated benchmark-based optimizers to compiled languages? Using function multiversioning, you could automatically test and swap optimizations without including a full compiler and either use it to optimize in production or have it emit statistics used to rebuild a smaller release binary.
1
u/Drawhoe Oct 19 '26
"than"
-1
u/No-Collar-Player Oct 19 '26
Than not then
I bet you earn 3x I do and know 5x than what I know. How?
-3
u/renderwares Oct 19 '26
Faster than Rust at 10x the memory usage.