Performance considerations of the EntityView module #1566
-
I'm curious about various performance aspects of EntityViews. I tried to at least skim through most parts of the documentation (deep diving into some sections) but I couldn't find much relevant info. I guess the performance aspects derive from the architecture but the description is quite high level so I'm rather asking explicitly. Basically, I would like to get a comparison of the EntityView approach to the "baseline" design. That is:
The aspects can be broadly divided into 3 categories. I'm kicking off some questions that come to my mind. Please add anything else which you might find relevant. Compile timeE.g. Is there a significant overhead of the annotation processor? (that is compared to the baseline setup) Anything else? Boot timeHere I guess there's the extra initial Anything else? RuntimeI'm especially interested in how reflection is used to populate entity views and how this compares to the baseline approach. My understanding is that entity views are similar to DTO projections, i.e. they bypass actual entity creation and so they shouldn't be worse reflection-wise than the baseline approach. Anything else? Many thanks in advance for your reply! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Obviously, the annotation processor comes with some overhead as it has to analyze entity view classes and generate code for them, but the overhead should be negligible compared to the overall compilation process. Apart from that, you can also skip annotation processing if you prefer generating classes at boot time.
The scanning in a Spring or CDI project might incur some overhead, but I have never heard of this being a problem in real apps. In Quarkus projects, scanning happens in the "deployment phase" which runs during application packaging, which is more like compile time than boot time. We could improve the scanning a bit with Jandex, but I'll only start looking into that if it really becomes a problem for someone who can actually show me a project where this is reproducible. If this becomes an issue for you, you could also disable scanning and write a class that registers all entity view classes to the configuration. Apart from that, the whole metamodel is built at boot time, which we could also build in parallel if necessary, but that also hasn't been an issue for anyone so far. If you don't use the annotation processor, depending on configuration, the entity view implementations are generated at boot time or on first use.
The only reflection part that happens during runtime is for instantiating the entity view objects. If this turns out to be a provable bottleneck for someone, we can also generate bytecode factories to speed things up, but if you look into the implementation, you will notice that it is very efficient already, also from an algorithmic perspective. What happens from a high level view is this:
Then, when you execute the query:
Overall, the actual code that runs should (1) in the simple cases be very similar to what you would write yourself, and (2) in the non-trivial cases be a lot more efficient due to special internal data structures and various optimizations. Hope that helps you understand what is happening behind the scenes. |
Beta Was this translation helpful? Give feedback.
Obviously, the annotation processor comes with some overhead as it has to analyze entity view classes and generate code for them, but the overhead should be negligible compared to the overall compilation process. Apart from that, you can also skip annotation processing if you prefer generating classes at boot time.