Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 312299 - Virtual table never converts back to spare array
Summary: Virtual table never converts back to spare array
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.0   Edit
Hardware: PC Windows All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Felipe Heidrich CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-10 12:47 EDT by Felipe Heidrich CLA
Modified: 2021-11-25 18:57 EST (History)
2 users (show)

See Also:


Attachments
patch (1.52 KB, patch)
2010-05-10 14:50 EDT, Felipe Heidrich CLA
no flags Details | Diff
patch (1.67 KB, text/plain)
2010-05-10 16:48 EDT, Felipe Heidrich CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Felipe Heidrich CLA 2010-05-10 12:47:16 EDT
this is followed up of bug Bug 129703


When a virtual table is created is starts using a spare array to store the items.

When items are added to the array the code compare the size of the array and the total number of items. When the size of the spare array is greater than half of the number of items the table replaces the spare array with regular array to save memory.

But when items are removed from the array, the table does not perform the same test and does not convert back to the spare array implementation.

here is a test case:

public static void main(String[] args) {
	Display display = new Display();
	final Shell shell = new Shell(display);
	shell.setLayout(new GridLayout());
	
	final Table table = new Table(shell, SWT.VIRTUAL);
	table.setItemCount(5);
	table.getItem(0).setText("item0");
	table.getItem(1).setText("item1");
	table.getItem(2).setText("item2");
	table.getItem(3).setText("item3");//table no longer keyed (more items than items nulls)
	
	table.setItemCount(10);//more nulls than items, should switch back to keyed (do the conversion before allocating a huge array)
	
	table.addListener(SWT.SetData, new Listener() {
		public void handleEvent(Event event) {
			TableItem item = (TableItem)event.item;
			int index = table.indexOf(item);
			item.setText("item-"+index);
		}
	});
	shell.pack();
	shell.open();
	while (!shell.isDisposed()) {
		if (!display.readAndDispatch())
			display.sleep();
	}
	display.dispose();
}
Comment 1 Felipe Heidrich CLA 2010-05-10 14:50:44 EDT
Created attachment 167781 [details]
patch

Notes:

The change from non-keyed back to keyed can be triggered by:
a) increase item count
b) decrease the number initialized items in the array 

But (b) can never trigger the change because removing an item from the array also decreases the item count. Note that the opposite is not true. Items can be added to the array without increasing the item count.

----
Other problem is that I decided to use a index to count of the exact number of non-null elements in the array to determine when to change to spare array. I could have used items.length but I decided not to because it does not reflect the actual usage of the array.
Comment 2 Felipe Heidrich CLA 2010-05-10 16:48:42 EDT
Created attachment 167815 [details]
patch

New patch, we are still not happy with the patch.

1) the _checkKeys need to be called from other places (like _removeItem())
Example case:
itemcount == 10 with 7 elements created (3 nulls in the array)
remove 5 items (calling table#remove(index))
item count 5, 2 elements (3 nulls) - this case should cause the table to switch back to be keyed.

2) application that add and remove items often (crossing the keycount>count*2 boundary many times) can suffer of bad performance.

On a side note, it seems that the whole keyed strategy should not run when item count is small (not sure exatly how big the table should be to start with the whole keys thing).
Comment 3 Eclipse Webmaster CLA 2019-09-06 16:12:00 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.
Comment 4 Eclipse Genie CLA 2021-11-25 18:57:14 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.