Datatable Poor Performance VS.NET 2005 too.. New Indexing engine failed
I have downloaded the Visual C# (Whidby-vs.net 2005) and have tested a sample program(Datatable with Large number of records).
Microsoft explained the new features of ADO. NET 2.0 will resolve this issue with the new indexing engine for datatables.
Results: Both VS. NET 2003 and VS. NET 2005 performs the same way and hence no improvement here.
Note:
1. In the sample program(found below) if you comment the statement (bolded and in red color) the entire operation was quick. This particular statements basically updates the row with some new value. I understand from VS. NET 2005 that they have resolved inserts/updates/deletes performance of datatables greatly. Please address this issue urgently.
2. Check this discussion too.http://www.devnewsgroups.net/group/microsoft.public.dotnet.framework.adonet/topic3383.aspxprivatevoid button1_Click(object sender,EventArgs e)
{
MessageBox.Show(DateTime.Now.ToLongTimeString());
DataTable tbl =newDataTable("TestTable");
tbl.RemotingFormat =SerializationFormat.Binary;
System.Type myDataType;
myDataType = System.Type.GetType("System.Int64");
DataColumn dc =newDataColumn("ID", myDataType);
tbl.Columns.Add(dc);
DataColumn dc1 =newDataColumn("Value", myDataType);
tbl.Columns.Add(dc1);
for (int i = 0; i < 100000; i++)
{
DataRow row = tbl.NewRow();
row["ID"] = i;
row["Value"] = i + 10;
tbl.Rows.Add(row);
}
MessageBox.Show(DateTime.Now.ToLongTimeString());
for (int i = 0; i < 100000; i++)
{
DataRow[] row = tbl.Select("ID=" + i);
row[0]["Value"] = 30;
}
MessageBox.Show(DateTime.Now.ToLongTimeString());
}
Select performance is not specifically improved for Whidbey.
The main performance gain you would see in Whidbey are in 2 areas:
a) Adding, deleting large number of rows in a table which have a PK.
b) RowFilter and Sort Operations on DataView.
However, to make your specific scenario faster, you have 2 options.
Option 1) Creating a primary key on ID column would make the Select run faster.
Option 2) If you cannot make the ID a primary key, you can create a single dataview, before the select like below.
//tbl.PrimaryKey = new DataColumn[] { dc }; --> Option 1DataView dv = new DataView(tbl); //> Option 2
dv.Sort = "ID ASC";Console.WriteLine(DateTime.Now.ToLongTimeString());
for (int i = 0; i < 100000; i++) {
DataRow[] row = tbl.Select("ID = " + i);
row[0]["Value"] = 30;
}
HTH,
Ravinder.