Relatively recently, annotations have appeared in Java that can replace XML files that are hated by everyone. Under normal conditions, I would never have asked this question, but since I keep my project on Google App Engine, in which, due to the Loading-request, the account goes in milliseconds. I optimized the code in every possible way to make it as fast as possible (first of all, I got rid of JDO in favor of the Low-level API), but somewhere I read the opinion that annotations also reduce the application performance. Annotations in Java are slower than XML configuration files?

    3 answers 3

    What does slower mean? Slower for what? At what point is slower? Do you mean slower to read? From a certain point of view, it may be slower, but on the other - faster.


    In theory, there should be no difference. But when the server starts to search for annotations, the server needs to bypass all classes and look for annotations in them, while parsing one XML is easier. On the other hand, this may be required only once at server startup, so this difference in speed does not matter. Unfortunately, I can not say anything about the life cycle of bins in GAE.

    • Slower in initialization. For example, a bean marked up by @ManagedBean and @SessionScoped annotation, and a bean, information about which is recorded in an XML file (<managedbean> ... </ managedbean>). Which of these classes will need more time to initialize? - Evgeniy
    • If the application has not been visited for 5 minutes, it is automatically unloaded from memory. At the first call in 5 minutes, a new VM starts, called instanse - this is in their terminology called Loading request. It turns out annotations in GAE can increase the duration of this very Loading request. - Evgeniy

    Slowly happening deploy applications. However, if the application server is not configured otherwise, scanning for the presence of annotations occurs anyway.

      The question is scant because annotations may to some extent increase their speed due to the writing of lines in the insides of this or that annotation itself, which is simply not found in the XML, because it is a bit difficult to answer the question