[hibernate-dev] Accessing annotation properties values

Sanne Grinovero sanne at hibernate.org
Fri Oct 5 08:16:27 EDT 2012


I have no clue on the performance impact in practice, but I'd be
careful in that area.

Generally I'd not discard the idea of slightly more complex code if it
avoids some more proxies and save some memory, but I don't know the
details here. Typesafety doesn't look like a strong argument to me as
any typo would be for sure detected by our tests. Of course I do value
typesafety a lot in terms of user API, but also think that for our
internal use I expect us to be more than capable to deal with it.

just my single cent, as it's not me writing that code ;)

On 5 October 2012 12:29, Steve Ebersole <steve at hibernate.org> wrote:
> I can only speak from what I have seen in the core code.  And yes,
> there I have often seen lookup for the same annotation multiple times.
> Is that worth caching?  I'd have to think so.  Creating javassist
> proxies is not cheap.
>
> On Fri 05 Oct 2012 03:59:45 AM CDT, Hardy Ferentschik wrote:
>>
>> On 5 Jan 2012, at 4:05 AM, Steve Ebersole wrote:
>>
>>> Probably you can cache it by AnnotationInstance, so maybe something
>>> like this instead:
>>>
>>> class AnnotationProxyBuilder {
>>>     private final Map annotationProxyMap = new ...;
>>>
>>>     public <T> T getAnnotationProxy(final AnnotationInstance
>>> annotationInstance, final Class<T> annotationClass) {
>>>         T annotationProxy = (T) annotationProxyMap.get(
>>> annotationInstance );
>>>         if ( annotationProxy == null ) {
>>>             annotationProxy = buildAnnotationProxy( annotationInstance,
>>> annotationClass );
>>>             annotationProxyMap.put( annotationInstance, annotationProxy
>>> );
>>>         }
>>>         return annotationProxy;
>>>     }
>>>
>>>     private <T> T buildAnnotationProxy(final AnnotationInstance
>>> annotationInstance, final Class<T> annotationClass) {
>>>         // as before...
>>>     }
>>> }
>>
>> Is it really worth caching by annotation instance? Are we in most cases not processing/visiting the instance once?
>> That said, I kind of like the proxy approach. It makes the code more compact (less if statements) and by using java.lang.Annotation
>> we get some type safety back (annotation.foo() instead of annotationInstance.value("foo")). The drawback of course is the
>> additional proxy overhead. I can see this idea as an evolution of the JandexHelper and would add it in there.
>>
>> Maybe Envers can lead the way and we can see how this approach turns out. Given that there is so much other stuff
>> still left to do on the metamodel side itself I don't think we should start retrofitting right now. There are other more important things to
>> do.
>>
>> --Hardy
>>
>
> --
> steve at hibernate.org
> http://hibernate.org
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev


More information about the hibernate-dev mailing list