r/java • • Oct 17 '26

Killing Reflection at Build Time: Avro, Codename One and Java Code Generation (Foojay Podcast #103)

https://www.youtube.com/watch?v=smHzWWNOyMU

In this episode of the Foojay Podcast, Dmitry Moskalyuk and Shai Almog compare how they cut runtime reflection out of very different projects.

Dmitry runs a backend model layer that takes JSON, XML, YAML and TOML and converts it all to Avro. His choice between Jackson and kotlinx.serialization came down to where the reflection cost actually hides. Shai works on the Codename One code generation pipeline, which aims for no reflection, no service loader and no Class.forName.

Topics include Jackson Blackbird versus kotlinx.serialization, the missing unknown-fields feature that sent one team back to Jackson, generated code (Lombok, Manifold, jOOQ), what Records and Project Leyden change, and build time cost versus runtime cost.

Available in your favorite podcast app and on YouTube:
YouTube: https://www.youtube.com/watch?v=smHzWWNOyMU

Disclosure: I host the Foojay Podcast.

24 Upvotes

21 comments sorted by

View all comments

7

u/SomeRandomDevPerson Oct 18 '26

Related: any experiences using Avaje generators?

7

u/lazystone Oct 18 '26

I've tried Avaje for a side project and I honestly don't understand why it's not more popular and talked about.

6

u/shai_almog Oct 18 '26

I used that previously when building up Lightrun. I liked it a lot, so we added something like that to Codename One. You can point to an OpenAPI, gRPC or GraphQL spec and generate stubs etc. with no reflection or runtime overhead.

It's a fantastic approach.

6

u/agentoutlier Oct 18 '26

It’s a fantastic approach that people act like it’s novel when the little guys have been doing it forever and only recently giant OSS projects have started picking it up.

I can point to dozens of projects where I personally convinced the maintainer to switch from annotation reflection to APT prior to every one embracing the build step (before quarkus, micronaut etc).

So that is why I had kind of had a nasty comment early about this not being a big deal that I deleted because I did not realize you do have some amazing stuff with the byte code to C and that you are targeting phones.

Otherwise I’m going to say and I know quite a bit about this that reflection is not that massively slower especially if the method or class names are static string literals. (eg the service loader btw and method handles)

For example JStachio (my project) is not that much faster than JMustache especially if the model is hashmap.

6

u/shai_almog Oct 18 '26

Yes. I didn't see the edited version, but during our conversation I specifically mentioned how amazingly well HotSpot etc. optimize reflection. There is some optimizer collateral damage as hotspot can't make some assumptions when you use reflection, but if you have a long running app it's reasonable.

Also with my background in observability, we literally couldn't do half of the stuff we do in the field of observability without reflection...

My problems with reflection are mostly conceptual and due to AOT/Client costs where the problems are more significant (e.g. obfuscation). I'm also looking at the small server with 15ms startup time overhead. Here every nanosecond counts and JIT just doesn't have time to warmup.