3

Context: I have a set of View/Presenters and I've noticed that for complex views I get some performance issues at the time of the InitializeComponent() call

Is there any way to instruct the spring container to pre-instantiate objects scoped as prototype? Something similar to a queue with the objects ready when the application requests them?

Sebastian Piu
  • 7,838
  • 1
  • 32
  • 50

1 Answers1

2

We had exactly the same problem. We also found that this performance overhead occured only the first time we requested a form from the container. We didn't find a clean solution, so we decided to write an initialization routine that runs in the background and requests all objects of type Form from the container. When this routine is finished, all forms open quickly.

Looking forward to a better sution, but this worked for us. Main disadvantage of this workaround is, that during the initialization routine, users might still experience some slow loading forms.

Marijn
  • 10,367
  • 5
  • 59
  • 80
  • I also noticed that the forms are slower the first time.. will post if I find another solution or I might end doing the same that you did as I have a splash screen where I could just request all forms as an additional step – Sebastian Piu Aug 04 '11 at 11:20
  • @Sebastian - what did you end up doing? – Marijn Aug 24 '11 at 09:51
  • @Marijin - Nothing so far, but I've got it on my queue. Have you checked the Pooling capabilities of spring? I thought of giving that a try but didn't find the time to do it – Sebastian Piu Aug 24 '11 at 11:28
  • @Sebastian: haven't thought about, but I don't think it will really help; pooling is about re-using objects (think database connections) that are expensive to create. I don't think you should do that for Forms, because you would have "cleanup" state before passing it along - that seems difficult. Besides, our observation was that we only had problems __the first time__ we request an instance from the container; the next time a form from the same class was created, it was created really fast. – Marijn Aug 24 '11 at 11:38
  • It could be that it has something to do with the vast amount of public properties that a form has; it might be that spring is scanning those using reflection the first time it processes an object definition. But I'm guessing here. – Marijn Aug 24 '11 at 11:40
  • have you tried using ngen to precompile the main exe? I've tested on my machine and it makes a noticeable difference at the time of loading the first time – Sebastian Piu Sep 05 '11 at 13:11
  • I'll give it a try later this week. – Marijn Sep 05 '11 at 13:23