Performance variation by populating view after addComponent()


I was wondering if there is any difference or performance impact in populating a layout and adding the component to window (or already attached component) vs adding the layout and then populating it.

Ex - VerticalLayout x =new VerticalLayout();
Label y = new Label();

// Adding already populated layout x to attached element
// (in this case window)


   VerticalLayout x  =new  VerticalLayout();

[/b] // Adding component x to attached element
// and then putting components into layout x
Label y = new Label();



Yes, there can be a difference, although usually a very small one - populating a layout before attaching it is faster. The extra cost comes from additional listener calls and possible checks on the server side etc. There is no difference in client side rendering performance as long as all the components are added before the layout is shown on the client.

If you only have a handful of components in the layout, the difference should be negligible, but if you have tens or hundreds, it can be noticeable.

The same also applies to populating container data sources before setting them as the data source of a Table or other component, where the difference can be even bigger.