Performance issue while scrolling the table.

Hi All,

I have a table with BeanContainer datasource attached to it. I am retreiving 100 records from the database and adding it to the datasource.

I have a factory class which extends DefaultFieldFactory. I am setting the factory to the table.

I have added validation on fields of the table. Validation is done in
createField method
of the factory class. I am using csvalidation add-on for this. Regular expression is used for validation.

Everything is working fine. Proper data is getting loaded and validation is also working.


Problem : when I scroll the table, it is taking too much time to render the table.

Please help me and share the possible reasons behind this performance issue.

I believe while scrolling, the data is taken from the datasource container and not from the database.
Is it correct?

Thanks in advance.

Please find my overriden
createField
method below:-

@Override
public Field createField(Container container, final Object itemId,
		Object propertyId, Component uiContext) {
	
	if ("businessdate".equalsIgnoreCase((String) propertyId)
				|| "valuedate".equalsIgnoreCase((String) propertyId)) {

			f = super.createField(container, itemId, propertyId, uiContext);

	} else {

		CSValidatedTextField field = new CSValidatedTextField(
			createCaptionByPropertyId(propertyId));

		      field.setRegExp("[0-9]

*“);
field.setPreventInvalidTyping(true);
field.setMaxLength(10);
field.setNullRepresentation(”");
field.setWidth(“100px”);

		     f = field;
	}
	
	f.setReadOnly(true);

	return f;
}

Yes, the data is taken from the data source of the Table.

You should probably try to find the root cause step by step, eliminating possible issues. A few hints for that:

  • Add the URL parameter
    ?debug
    to the URL and see in the debug console whether the time is spent getting a response from the server or on the UI
  • Simplify your code step by step, e.g. first removing the field factory and checking if that has an effect
  • Remove columns from the data to see if one of them is causing extra delays for some reason
  • etc.

Using a profiler might also help if the issue is on the server side.

If you are using an ORM framework that may perform lazy loading of fields from the database even though the top-level entities are in memory, that might also be the culprit.

Thank you Henri. I will follow your suggested approach.

Following is my analysis:-


1)
with no FieldFactory : On scroll of the table, records are shown very quickly.


2)
with custom FieldFactory: I got following result in different scenario.


(a)
overriding the method createField. I am not doing anything here except calling super.createField() method. It is equivalent to not adding any custom FieldFactory. It is taking more time to show the records. Time taking is almost 100% more than that of the first scenario.

@Override
public Field createField(Container container, final Object itemId,
		Object propertyId, Component uiContext) {

	Field f = super.createField(container, itemId, propertyId, uiContext);

	return f;
}


(b)
overriding the method createField. I am trying to cast Field to TextField. Casting of the field is adding some more delay.

@Override
public Field createField(Container container, final Object itemId,
		Object propertyId, Component uiContext) {

	Field f = super.createField(container, itemId, propertyId, uiContext);

	if ("businessdate".equalsIgnoreCase((String) propertyId)
			|| "valuedate".equalsIgnoreCase((String) propertyId)) {

		f.setWidth("60px");
	} else {
		TextField tf = (TextField) f;
		tf.setNullRepresentation("");
		tf.setWidth("100px");
	}

	return f;
}    


(c)
Finally when I use CSValidatedTextField for adding validation, it again adds some more delay.


These results show that I can’t avoid this delay. But I need to implement validation on table fields. So is there any way to add validation on table fields, without performance issue?

An editable field is always going to be heavier to render than just a string. You can return null from the field factory to use just an uneditable String (from toString()) for the cells that do not need editing or other custom handling.

The time you quote of many seconds sounds like a lot, though. I assume you have a very large number of fields visible. Maybe also the large number of regular expressions processed etc. slow down the client somewhat.

Assuming you are using scrolling (and thus lazy loading) of the table (i.e. not setting page size 0), you could try to reduce the cache rate (setCacheRate(double)) which controls how much data is pre-rendered on the client side. The goal is to enable smoother scrolling, but if the data is heavy to render, this approach can backfire. Try values in the range 0-0.5 and see how they affect rendering speed and scrolling.

starting the application in debug mode had given me the knowledge about caching of records. Now
setCacheRate
has improved the performance somewhat. I tried with values between 0 to 5 and have seen the overall impact. Finally setting 0.1. I will try with returning null from the fieldfactory.
Thanks a lot Henri for improving my knowledge.