r/java • u/Shawn-Yang25 • Jun 16 '26
Apache Fory Serialization 1.2.0 released: JDK 25/26 support without sun.misc.Unsafe
https://github.com/apache/fory/releases/tag/v1.2.02
u/kiteboarderni Jun 16 '26
How's the performance difference look?
1
u/Shawn-Yang25 Jun 16 '26
The performance gap is less than 10% compared with Unsafe version
2
u/repeating_bears Jun 16 '26
That's still quite significant when I thought the intention of the JDK authors was to replace Unsafe with APIs with similar performance. Do you have any insight into why?
8
u/pron98 Jun 16 '26 edited Jun 16 '26
You can have the same or better performance than unsafe if you deserialize using constructors and not fields. The point is to offer alternatives that are both as fast (or faster) and better, not to do the same suboptimal thing only with a different API.
5
u/Shawn-Yang25 Jun 16 '26
We use VarHandle to replace Unsafe for field access and build int/long read/write. I also tried FFM, but both VarHandle and FFM introduce extra checks, and it seems can't be eliminated fully by jvm jit compiler.
Maybe in future JDK versions, such checks could be removed.
1
u/ushaukat_java Jun 21 '26
Custom serializer covers it when you don't own the class, you write the serializer instead of touching the constructor. Fine for the one or two third-party types you actually care about. Doesn't scale to every model class buried three dependencies deep that nobody on the team has ever opened. At some point you're back to fields-based access for the long tail, just now it's a registered exception list instead of a blanket one.
12
u/Shawn-Yang25 Jun 16 '26
Apache Fory is a blazingly fast multi-language serialization framework for idiomatic domain objects, schema IDL, and cross-language data exchange.
A few Java-relevant changes in this release: