The record mapper factory sounds like a really good idea. Then it would be possible to plug in a "CachingReflectionMapper" for example to do what I was thinking. Or just maintain a couple of manual mappers for the most used pojos and not have to remember to always call the mapper manually, but continue using .into.If the generated mappers instantiate a DAO for re-use,
wouldn't it just be possible to have a global cache with Map<Class, ReflectionMapper>. Then whenever the class is encountered, it checks the cache and re-uses the reflection mapper (which shouldn't need to do too much work now it knows the class already). But I don't know enough about the internals of JOOQ to know if this would work. I'm sure there would be some multithreading and classloader issues that could arise.
I guess the mapper factory would be an ideal solution because multithreading and class loader issues wouldn't then have to be handled by JOOQ.
But I should really start using JOOQ 3 first, it might help performance out so none of this is needed :).
If the generated mappers instantiate a DAO for re-use,It's the other way round. The generated DAO reuses its internal mapper reference. Unless you aren't referring to the existing functionality.
Well, in high-throughput scenarios, there is still a considerable amount of CPU waste, when mapping "into" POJOs...
> [...] you could cache the results of the reflection
> (really it is the whole "parsing" algorithm, whichPlease make sure that the class objects don't get strongly
> uses reflection) globally for each class, so it
> re-uses the same generated "algorithm" whenever it
> sees the same class.
linked to from the cache.
This is surprisingly hard to get right actually. I once
tried to do something like that, and found that garbage
collection and weak references and WeakHashMaps somehow
do something subtly different than I had thought. In the
end, I punted and declared Introspector "barely sufficient
for the use case at hand".
Since caching reflection is easy to get wrong, if Jooq is
ever going to use that, the hard-to-get-right aspects of
this should be solved by Jooq. Could be done by
- having (or linking to) a full in-depth description
how to do it right,
- offering a reflection cache data structure that does it
right,
- make Jooq's API accept the reflection info, but manage
the cache inside Jooq (and say in the Javadoc that the
code computing that reflection info must never retain
any references to that info).
I don't see why it needs weak references? I would just control the cache manually within the application and if I need to get rid of all references then call a clear() method.
Of course if it was inbuilt in Jooq and on by default it would be a different story.
Still, weak hash maps I don't think would solve all issues. It might just prevent memory leaks, which I don't think would be a major issue unless you are using "into" for a growing number of classes... which I guess might happen in an osgi environment or webapp if you happen to be using Jooq from the shared classpath. But in that case you're asking for trouble if you wanna cache application classes in the shared classloader classpath... or something...
this stuff does my head in...
--
You received this message because you are subscribed to the Google Groups "jOOQ User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jooq-user+...@googlegroups.com.
You'd want to use CacheBuilder, which allowed us to pull away from the limitations of and not abuse the Map interface.
If you want to embed an LRU cache, which I don't think is the case, [...]
many prefer its predecessor (ConcurrentLinkedHashMap) as a lighter-weight dependency to shade. We reworked Guava's implementations based on that project.
As a user, I'd prefer a plugin scheme when possible to tease apart complexities. It would be nice if jOOQ provided a good implementation or two, which might require me to add a few more dependencies to the project, to avoid repeated work.