Stuart Douglas commented on WELD-1100:
So I have had some thoughts about how best to do this, and some idea's of the
potential benefits it can provide. As much as possible we should be avoiding using
java.lang.reflect.*, as it is really slow. Even things that you would expect to be fast
such as accessing a member on an annotation are actually relatively slow.
At boot time we use reflection for a few different things:
*Identifying CDI scopes, produces, injection points etc*
This can be completely replaced with Jandex, as there is no spec requirement to use
java.lang.reflect.*. I think in practice this would mean a move away from using
WeldAnnotated* to determine this information, which I think is a good thing, as I think
WeldAnnotated is doing to many things at the moment.
*Building the AnnotatedType used in ProcessAnnotatedType*
Even though this is spec mandated, I think there are a few different things we could
explore here to improve performance.
1) May the AnnotatedType implementation lazy. This will not help much if there are
portable extensions that need to examine field/method level metadata, but it is a start,
and will be a big win if we come up with a solution to CDI-43.
2) Use our own annotation implementations instead of the JDK's annotations. Because we
have the Jandex indexes we can tell which Annotated* have no annotations, and can avoid a
reflection call to Class#getDeclaredAnnotations() that would just result in an empty set.
We can also investiate using our own annotation generation (think
AnnotationInstanceProvider from deltaspike) and generate annotations that do not involve
any reflection, and do not involve JDK wide locks as part of the creation. The JDK
reflection impl is full of locks, and even though they are not held for long they still
have a noticeable impact on parallel boot performance.
*Don't use annotations as part of internal data structures*
I already started this with org.jboss.weld.resolution.QualifierInstance as part of the
1.1.7 performance work, which provided a big boost to performance (especially resolving
observer methods at runtime)
We also need to be careful with these changes that we do not impact the performance of
weld-se or weld-servlet, which will be stuck using a reflection based implementation of
whatever annotation provider SPI we come up with.
Add annotation provider SPI
Issue Type: Feature Request
Reporter: Stuart Douglas
JDK annotation based reflection is slow, it would be good if we could leverage Jandex to
use AS7 existing jandex annotation indexes.
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
For more information on JIRA, see: http://www.atlassian.com/software/jira