ViewScope Vs UIScope

Hi All,

We are in the process of migrating a huge legacy application originally written in JSF to Vaadin 7.7.9. After noticing delays in getting various pages rendered, we used AppDynamics to profile the server and noted that Vaadin Spring Beanstore create method takes significant amount of time.

  1. What are the factors which can affect Bean creation with Vaadin Spring?
  2. Considering that we have a good number of Views, should we consider making our Views UIScoped rather than ViewScoped to avoid the creation of Bean everytime till the user refreshes the screen or session end?
  3. If we go with more UIScoped beans, this will lead to more memory footprint. When will the obejcts related to ViewScope ideally be ready for garbage collection?
  4. What are the general good practices for getting a UI rendered fast? I have read about avoiding Nested vertical layouts etc. but are there any other things to consider when using Spring Vaadin addon?

Sajan

34215.png

Hi Sajan,

sorry for the late reply.

This is a very generic question and therefore hard to answer. But let’s say generally that you usually create your beans late and lazy and within some scope, and so often times resources need to be cleaned up (have a look at DisposableBean).
If creating your beans takes a lot of time, then please check if they are properly decoupled from the back-end. Just creating a UI is quick; but it’s a different story if you query the database for a full table dump on entering a View, for example.
2)
If you have a ‘good number’ of views, this would call for making them ViewScoped, as you don’t want to accumulate all those views’ memory consumptions for each UI (and then accumulate all those UI’s memory consumptions for one session’s memory footprint!).
Of course, this mandates proper resource handling when creating / disposing of the beans.
3)
UIScoped beans: estimate first if you really want that and can afford the memory footprint. It goes against the norm - have good reasons for that. ViewScope: use a Navigator to leave the view, implement Spring’s DisposableBean – View and resources are ready for GC.
4)
not really a good fit for the Add-Ons part of the forum. There’s nothing on the client side that’s different from a client side being delivered by a non-Spring-controlled Vaadin application. So the general rules for Vaadin applications apply: don’t use old browsers with bad JS implementations; don’t nest layouts too deeply and if you have to do it, go the extra mile and consider using CssLayout. When querying a database, don’t load it all at once, go for some lazy loading mechanism; use the Grid over Table.
5)
As you have a lot of views, for rapid development time (and better UI decoupling) have a look at Vaadin Designer to create the UI part of the Views with it. Give names only for Components you need access to in the (derived in the OO sense) implementation class with code.

Hope it helps,
–Enver