How to improve Guice startup performance

Well, I know that my calculations are not objective and so on, but in any case, I can not wait to wait so much time when performing my unit tests:

It takes about 7 seconds to initialize to run my swice swice application. This is a simple IRC client. At this moment, the connection is not open, I have not even named the classes java.io or java.net yet. I tried to narrow down what exactly is wrong, and I get that Guice uses 5.8 seconds (on average) to create an injector using the 2 modules that I use (one normal module and one built with FactoryModuleBuilderinstalled in the original module).

When I remove all modules (therefore mostly just for calling and for sure Guice.createInjector()), it still takes 3.5 seconds.

The version of Guice I am using is 3.0 rc2. My computer, of course, is not the latest, but it is still not older than three years.

So how can I improve Guice performance if possible?


For reference, here is the main method that I use, calling 3.5 seconds. Subsequent calls take 0.01 seconds.

public static void main(String[] args) {

    long t = System.currentTimeMillis();
    Injector injector = Guice.createInjector();
    long t1 = System.currentTimeMillis();
    System.out.println(((t1 - t)) / 1000.0);
}

And the result

3.578
+4
source share
1 answer
  • You do not need to use Guice in unit tests. If you need it, they are probably not unit tests (which test things separately), or you are not using Guice correctly, or both.
  • Guice - , - - . ( 3.0 rc2) Injector Guice.createInjector() 100 .
+4

All Articles