C
charlesfr.rey
Anybody experienced this ?
It's not noticeable if you don't call getAnnotation often, but if
somehow you need to do this hundreds or thousands of times, there's a
good chance you'll notice it.
I had to implement my own Annotation cache (data structure: Map<Field,
Map<Class<?>, Annotation>>() ), but what I don't understand is that it
should already cache the info, looking into the JDK 5 source, in
Field.java, we have:
public <T extends Annotation> T getAnnotation(Class<T>
annotationClass) {
...
return (T) declaredAnnotations().get(annotationClass);
}
private transient Map<Class, Annotation> declaredAnnotations;
private synchronized Map<Class, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) {
declaredAnnotations = ... parse annotations ...
}
return declaredAnnotations;
}
So, it should cache the annotations, but experience shows that it
doesn't.
Now, what's possible is that the JVM 5 that I have was not built from
the source code above ... ? Or am I missing something in the code ?
Using my own annotation cache (for Fields), performance is 20-25x
faster.
It's not noticeable if you don't call getAnnotation often, but if
somehow you need to do this hundreds or thousands of times, there's a
good chance you'll notice it.
I had to implement my own Annotation cache (data structure: Map<Field,
Map<Class<?>, Annotation>>() ), but what I don't understand is that it
should already cache the info, looking into the JDK 5 source, in
Field.java, we have:
public <T extends Annotation> T getAnnotation(Class<T>
annotationClass) {
...
return (T) declaredAnnotations().get(annotationClass);
}
private transient Map<Class, Annotation> declaredAnnotations;
private synchronized Map<Class, Annotation> declaredAnnotations() {
if (declaredAnnotations == null) {
declaredAnnotations = ... parse annotations ...
}
return declaredAnnotations;
}
So, it should cache the annotations, but experience shows that it
doesn't.
Now, what's possible is that the JVM 5 that I have was not built from
the source code above ... ? Or am I missing something in the code ?
Using my own annotation cache (for Fields), performance is 20-25x
faster.