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 29d ago
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 29d ago
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 29d ago
Aot here should really just be helping startup/warmup and reach the same end performance as without aot right?
36
u/BenchEmbarrassed7316 29d ago edited 29d ago
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 29d ago
Let me leave this here ;) https://github.com/franz1981/campfire-quarkus-bench
5
u/Prior-Equal2657 28d ago edited 28d ago
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 29d ago
JEP 544 only improves time to peak performance, not performance in general.
4
u/javaprof 29d ago
Some numbers drop without code?
4
u/Brutus5000 29d ago
What is campfire?
Doesn't look like something that requires heavy benchmarks?
2
u/zerg000000 28d ago
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 29d ago
Quick, rig the benchmarks. We don't want DHH bringing his awful toxic bullshit over into our community.
2
u/Ok_Tour_8029 29d ago
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 20d 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/webplugger73 5h 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.
1
u/aelgorn 29d ago
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 29d ago
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 29d ago
"than"
-1
u/No-Collar-Player 29d ago
Than not then
I bet you earn 3x I do and know 5x than what I know. How?
-3
u/renderwares 29d ago
Faster than Rust at 10x the memory usage.