Adam Bien's Weblog

What Is Faster: Parsing a java.util.Properties Or Invoking Class#getAnnotation()?

I'm building an EJB 3.1 capable ServiceLocator, which works with the global JNDI names (portable and standardized version JNDI-names needed to lookup a local, remote, or even no-interface-view interface) . The implementation relies on parsing java.util.Properties to fetch the current EAR and EJB-JAR (module) names - both cannot be derived via reflection. I was concerned about the performance of parsing and accessing the properties from a file and fired up the Netbeans 6.5 profiler.

I wasn't even able to find the java.util.Properties in the hotspot list at all. ...the reason was - it is lightening fast (took only about 4.5 ms...).

The ServiceLocator 2.0 :-) accesses the annotations as well - which turned out to be the real hot spot. The first access to the annotation takes 55 ms. It is the method Class#initAnnotationsIfNecessary (indirectly invoked by Class#getAnnotation), which takes so long. It uses Sun's internal class sun.reflect.annotation.AnnotationParser, which in turn creates a dynamic proxy. The creation of the dynamic proxy (Proxy#newProxyInstance) takes 44 ms.

The exact performance was: 

55 ms Class.getAnnotation
4.43 ms Creating, loading and parsing  java.util.Properties (two String entries) 


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License