Hasty Briefsbeta

Protobuf Meets Valhalla: Hacking with Java Value Classes (JEP 401)

8 days ago
  • #Java
  • #Protobuf
  • #Valhalla
  • Protobuf meets Valhalla: Experimenting with Java Value Classes (JEP 401) for Protocol Buffers.
  • Value classes lack identity, have no object headers, and offer better memory layout and cache-friendliness.
  • Potential benefits for frameworks like protobuf and gRPC include reduced overhead, better locality, and lower allocation pressure.
  • A protoc plugin was created to generate value-class-based protobuf messages, focusing on immutable value classes and direct wire-format parsing/serialization.
  • Benchmark results showed improvements in parsing (3-8% faster) and field access (up to 15% faster for large arrays), but sorting became 2×–3× slower due to copying.
  • Limitations include lack of production readiness, dependency on preview/EA JDKs, and no full protobuf runtime compatibility.
  • Conclusion: A fun experiment, not ready for production, but highlights potential benefits for frameworks handling many small immutable objects.