• Re: Java can be faster than Rust

    From Ross Finlayson@ross.a.finlayson@gmail.com to comp.lang.java.programmer on Thu Nov 26 08:02:09 2026
    From Newsgroup: comp.lang.java.programmer

    On 10/19/2026 02:25 PM, Mild Shock wrote:
    Hi,

    Yeah interesting. Java the old lady of 20-30 years,
    having features like maxMemory() that others lack?

    Bye

    BTW: In some corners people don't do PGO anymore
    because GCC23 has become better or something.

    Stefan Ram schrieb:
    | The tech community is actively discussing the Campfire framework - a
    | project originally written in Rust that saw significant performance
    | gains after being ported to Java. While this outcome surprised many
    | given Rust's bare-metal execution model, it highlights Java's robust
    | runtime optimizations and sets the stage for the highly anticipated
    | JEP 544 (Ahead-of-Time Code Compilation).
    |
    | The Campfire Context: Why Java Can Beat Rust
    |
    | The performance advantage in the Java port of Campfire stems from
    | specific architectural realities rather than raw CPU processing speed:
    |
    | o Garbage Collection vs. Explicit Memory Management: Rust relies on
    | strict ownership and explicit allocation/deallocation. In highly
    | dynamic, short-lived object scenarios, Java's modern garbage
    | collectors (like ZGC or G1) can allocate memory incredibly fast via
    | thread-local allocation buffers (TLABs), deferring the cleanup cost.
    |
    | o Just-In-Time (JIT) Dynamic Optimization: Java's C2 compiler profiles
    | the application while it runs. It performs deoptimization, aggres-
    | sive inlining, and escape analysis based on real-world runtime be-
    | havior - optimizations that a static, ahead-of-time compiler like
    | Rust's rustc cannot always predict.
    |
    | JEP 544: Ahead-of-Time (AOT) Code Compilation
    |
    | JEP 544 introduces a formalized framework for Ahead-of-Time (AOT)
    | compilation into the standard OpenJDK pipeline. It builds heavily on
    | the groundwork laid by Project Leyden to address Java's historic
    | weaknesses without sacrificing its runtime strengths.
    |
    | To understand how JEP 544 shifts the paradigm, it is best evaluated
    | across key multi-attribute technical metrics:
    |
    | .--------------------------------------------------------------------.
    | | JEP 544 Architectural Comparison |
    | |--------------------------------------------------------------------|
    | |Architectural | Traditional JIT | JEP 544 (AOT | Impact on |
    | |Metric | (HotSpot C2) | Compilation) | Frameworks like |
    | | | | | Campfire |
    | |--------------------------------------------------------------------|
    | |Startup Time | Slow. The JVM | Instantaneous. | Crucial for |
    | |& "Warmup" | must interpret | Pre-compiled | cloud-native |
    | | | bytecode and | native machine | scaling and |
    | | | compile hot | code executes | microservices. |
    | | | methods | immediately | |
    | | | iteratively. | upon boot. | |
    | |--------------------------------------------------------------------|
    | |Memory | High. Requires | Low. Strips out | Lowers |
    | |Footprint | extra memory to | heavy runtime | infrastructure |
    | |(RSS) | store the JIT | compilation | costs |
    | | | compiler | machinery, | significantly. |
    | | | infrastructure. | reducing base | |
    | | | | memory usage. | |
    | |--------------------------------------------------------------------|
    | |Peak | Extremely High. | High to Very | Bridges the gap |
    | |Throughput | Optimized | High. Uses | between static |
    | | | continuously | stored | binaries and |
    | | | using live | profiling data | dynamic |
    | | | production | (PGO) to match | optimization. |
    | | | telemetry. | JIT performance | |
    | | | | closely. | |
    | '--------------------------------------------------------------------'
    |
    | Key Thoughts on JEP 544's Strategic Approach
    |
    | 1. It Avoids the "Closed-World" Trap
    |
    | Unlike GraalVM Native Image, which enforces a strict "closed-world
    | assumption" (restricting dynamic class loading and reflection), JEP
    | 544 aims for a flexible AOT model. It allows developers to compile
    | critical parts of the application ahead of time while maintaining
    | standard Java compatibility.
    |
    | 2. Profile-Guided Optimization (PGO) is Mandatory
    |
    | Static AOT code is inherently less optimized than dynamic JIT code
    | because it lacks runtime context. JEP 544 solves this by leaning into
    | Profile-Guided Optimization. By feeding training run data into the AOT
    | compiler, the resulting binary retains the aggressive optimizations
    | (like speculative inlining) that allowed the Campfire Java port to
    | outpace Rust.
    |
    | 3. The Future is Hybrid
    |
    | The ultimate goal of JEP 544 is not necessarily to replace JIT
    | entirely, but to create a hybrid deployment model. Applications can
    | boot instantly using AOT-compiled code, and as the application warms
    | up, the JIT compiler can selectively re-compile performance-critical
    | hot spots to achieve peak throughput.

    Lines marked with "| " come from my editing, where I start by writing
    prompts for the chatbot and then edit the generated texts and format
    them for Usenet. The chatbot might make mistakes and misrepresent
    or invent facts.




    It's just an adaptive algorithm. Everybody knows that given the
    distribution of the input that an "ideal" algorithm/data-structure
    can be given, then also that things change, so, there's no perfect
    "adapative algorithm", with regards "profile-directed optimization"
    and its online cousin "feedback-directed optimization", from accounts
    of what's called "machine-learning" about expert-systems, statistical inference, neural nets & feedback, which anybody knows.


    The "adaptive algorithm" is what that's called, and brings all the
    machinery about the maintenance and particularly the re-organization
    into play.

    Then printing out a player-piano tune only plays one tune, though
    often it may be "vertically scaled" by adjusting the tempo.

    (I once had access to a "player-piano" like for "The Entertainer"
    from "The Sting".)

    Java can be faster than Java - ..., not much is faster to run
    and slower to change than hardware, or, "in silico", though with
    accounts these days to "optical" circuits besides, which can
    broadcast and scatter/gather in constant instead of log time.


    One may aver that having a small array of small
    content-associative-memory would be better than a giant tray of
    embarrassingly parallel
    simplistic units. The content-associative-memory is itself a very
    "adaptive" data-structure, naturally.




    --- Synchronet 3.21e-Linux NewsLink 1.2