Does this technique implies that the use of the retrieved data is done in the same method as the one calling the createQuery and query execution? Or at least close enough? Because if the query results are passed around a few layers, I don't see how these bytecode analysis can be done (effectively).
Not necessarily. I think the core implementation would be some form of escape analysis: we can try to figure out up to where the data is affecting other code in some limited boundary depending on how much we want to optimize. We would then avoid doing any dangerous change (like fiddling with results leaking into unknown other functions which are "out of sight") and focus on the trivial cases. I somehow suspect that just addressing the trivial cases there is quite some benefit to harvest: for example to start from the essential, I guess it's likely that most people load a list of entities but to read only a subset of their properties.
BTW looking at bytecode at runtime, the concept of "layers" gets blurry. I think (wishfully) that it's a beneficial layer: hotspot will already have removed all the framework cruft which isn't of interest.
|