r/java • • Aug 18 '26

AutoValhalla: automatically turn your plain classes and records into value classes!

Automatically turn your plain classes and records into value classes!

Add @AutoValhalla annotation to classes or records in your JDK1.5+ codebase:

@AutoValhalla
public final class Point {        // class must be final
    public final int x;           // with final instance fields
    public final int y;
    public Point(int x, int y) { 
        this.x = x; 
        this.y = y; 
    }
}

@AutoValhalla
public record Currency(String code) { }  // or a record class

When your app is run on Valhalla-enabled JVM with auto-valhalla javaagent, these classes are automatically turned into value classes.

More info: https://github.com/thunkware/auto-valhalla/tree/auto-valhalla-0.1.0

edit: there is now a maven plugin for converting at build time. https://github.com/thunkware/auto-valhalla/tree/auto-valhalla-0.2.0

40 Upvotes

54 comments sorted by

View all comments

Show parent comment

1

u/alex_tracer Aug 26 '26

I also work in fintech..., and I know we don't really care about the performance improvements from valhalla. Like anything else, I'd wager that the vast majority of fintech applications also wouldn't get much of a benefit.

There are many different types of fintech projects, with different contexts and requirements. Like processing market events in a dozen of microseconds (do not confuse with milliseconds) in Java.

I've provided a link to example class (in public domain) that can potentially benefit from value classes in future (not right now because of null flag). This and some similar cases become very important when you have to support things like an order book with 10k+ levels and 100k+ entries.

1

u/OwnBreakfast1114 Aug 26 '26

Don't get me wrong, I absolutely agree with you. I'm just pointing out that "processing market events in a dozen of microseconds" application is probably the smallest subset of fintech applications (most of which are probably incredibly unoptimized back office random stuff applications). Even our real-time payments application, which is far more performance sensitive than random back office applications, but nowhere near as performance sensitive as "processing market events in a dozen of microseconds" application doesn't care about valhalla from a performance perspective very much.