r/java • u/maxxedev • 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 classWhen 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
View all comments
Show parent comment
1
u/OwnBreakfast1114 Aug 26 '26
I feel like developers focus on attention on things that don't matter plenty of times. Value classes are really not going to make a difference for the majority of developers from an application performance perspective. Removing a single unnecessary db call will probably yield 100x the raw performance improvements value classes will bring for many applications.
I'm actually far more excited about the semantics as the semantics can be used to improve the developer experience. Records, pattern matching, sealed classes are all features that probably do have performance improvements (against the original constructs they replaced), but definitely aren't released for the performance. Simplicity and correctness are also features. Features, in my opinion, are far more important, compared to language performance for the vast majority of applications.
I also work in fintech (full on payment processing and card network integrations), 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.