1 Reply Latest reply on Jun 15, 2010 6:58 AM by Nicklas Karlsson

    Weld SE performance of Instance<..>

    Francois Swiegers Newbie

      Good day,

      I'm using Weld SE. I seem to run into performance issues once the number of managed instances go beyond 1000 when using the Instance<> mechanism to look references up programmatically.

      Here is a small test case:

      public static class MyBean {
           private String txt = "default";
           public MyBean(Instance<AnotherBean> anotherBean) {
                AnotherBean ab = anotherBean.get();
           MyBean(String txt) {
               this.txt = txt;
           public String toString() {
                return txt;
           public static class AnotherBean {

      Then run the following:

      private Instance<MyBean> mybean;
      long time = System.currentTimeMillis();
      for (int k = 0; k < 10000; k++) {
           MyBean mb = mybean.get();
      System.out.println("time " + (System.currentTimeMillis() - time)
                          + " ms");

      Now I know performance tests are subjective to a lot of environmental factors, but using this test, I get times of around 100,000 ms to load up 20,000 objects. That seems quite excessive as these beans are of the simplest kind. Using direct instantiation of 20,000 objects in Java rarely takes more than 10 ms on my machine (it often reports as 0 ms).

      For another comparison, if I wrap this test case in a servlet and let Resin's CANDI at it, then this operation takes about 150 ms.

      I'm using the latest Weld 1.0.2-SNAPSHOT, but the performance on 1.0.1-Final is similar.

      Is there anything I can do to improve Weld's performance in this scenario?