Panels clear() method extremely slow

4 views
Skip to first unread message

Granat

unread,
Apr 19, 2007, 9:44:52 PM4/19/07
to Google Web Toolkit
Hi

I noticed that clear() in panels are slow. Extremely slow on very
large lists. So I took a look at the code and found out why.

The clear() method loops through all children, removing them one by
one. But the thing is that the remove() method does not run in
constant time but linear, because it has to find the index of the
child first, which gives a quadric time for clearing (worst case).
This isn't noticeable for small lists but when you come up to a few
hundreds+ it will actually take seconds and lock up the page.

Will there be a fix for this? A simple fix in my opinion would be to
change clear() not remove the children one by one, but instead use
separate code to actually clear it all at once.

It would also be nice if the remove(Widget w) could be brought down to
constant time.

By looking at the implementation, I was able to bring down the
clearing to linear time of AbsolutePanel's clear() by creating a new
class extending AbsolutePanel and overwriting the clear() method:

public void clear()
{
WidgetCollection children = getChildren();
for (int i = getChildren().size()-1; i >= 0; --i) {
disown(children.get(i));
children.remove(i);
}
}

I haven't checked if this works with other panels too, but it should.

Anyway, my question is, will this be fixed?

mP

unread,
Apr 21, 2007, 11:57:53 PM4/21/07
to Google Web Toolkit
Without looking at the code, i would guess its a problem with the
WidgetCollection iterator passing the last visited widget rather than
its actual index.

mP

unread,
Apr 23, 2007, 12:01:09 AM4/23/07
to Google Web Toolkit

On Apr 22, 1:57 pm, mP <miroslav.poko...@gmail.com> wrote:
> Without looking at the code, i would guess its a problem with the
> WidgetCollection iterator passing the last visited widget rather than
> its actual index.

to the WidgetCollect.remove() method.

doh.

Reply all
Reply to author
Forward
0 new messages