DataRow Performance Bottleneck

  • Thread starter Howard Weisberg
  • Start date
H

Howard Weisberg

Our ADO.Net application was spending almost all its time
in the following line of code:

object dataColumn = row.ItemArray[column];

where row is a DataRow and column is an int.

We changed the line to the following:

object dataColumn = row[column];

This increased the performance by more than a factor of
25. Why did this happen? Is the performance hit in using
ItemArray documented anywhere?
 
D

David Browne

Howard Weisberg said:
Our ADO.Net application was spending almost all its time
in the following line of code:

object dataColumn = row.ItemArray[column];

where row is a DataRow and column is an int.

We changed the line to the following:

object dataColumn = row[column];

This increased the performance by more than a factor of
25. Why did this happen? Is the performance hit in using
ItemArray documented anywhere?

Excelent observation. And proves that you should always profile your code.

I don't think it's documented, but it really shouldn't be. Wether this
method is fast or slow depends on implementation details which can and
should change in future versions.

Here's what I think is happening:

row.ItemArray returns an array of objects. I may simply be a reference to
the objects stored in that row, but probably not. I think the objects are
really stored in columns, not in rows. Probably what happens is that ADO
creates a new array of with as many elements as the row has columns,
iterates through all the columns in that row and copies the column value
into the array. It then passes a reference to the array out to the
application, which then picks one element out of the array, and discards the
rest.

David
 
H

Howard Weisberg

Thanks -- that seems very reasonable.
-----Original Message-----

Howard Weisberg said:
Our ADO.Net application was spending almost all its time
in the following line of code:

object dataColumn = row.ItemArray[column];

where row is a DataRow and column is an int.

We changed the line to the following:

object dataColumn = row[column];

This increased the performance by more than a factor of
25. Why did this happen? Is the performance hit in using
ItemArray documented anywhere?

Excelent observation. And proves that you should always profile your code.

I don't think it's documented, but it really shouldn't be. Wether this
method is fast or slow depends on implementation details which can and
should change in future versions.

Here's what I think is happening:

row.ItemArray returns an array of objects. I may simply be a reference to
the objects stored in that row, but probably not. I think the objects are
really stored in columns, not in rows. Probably what happens is that ADO
creates a new array of with as many elements as the row has columns,
iterates through all the columns in that row and copies the column value
into the array. It then passes a reference to the array out to the
application, which then picks one element out of the array, and discards the
rest.

David



.
 
K

Kevin Yu [MSFT]

Hi Howard,

I agree with what David said. ItemArray property will generate a new object
array and put all the values of the fields into it. So it's always a little
bit slower than use Item[] property.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

--------------------
| Content-Class: urn:content-classes:message
| From: "Howard Weisberg" <[email protected]>
| Sender: "Howard Weisberg" <[email protected]>
| References: <[email protected]>
<#[email protected]>
| Subject: Re: DataRow Performance Bottleneck
| Date: Thu, 6 Nov 2003 14:35:20 -0800
| Lines: 54
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Thread-Index: AcOktkJixdUuF6uqTGm+xSOInLjn5g==
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:65695
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet
|
| Thanks -- that seems very reasonable.
|
| >-----Original Message-----
| >
| >| >> Our ADO.Net application was spending almost all its time
| >> in the following line of code:
| >>
| >> object dataColumn = row.ItemArray[column];
| >>
| >> where row is a DataRow and column is an int.
| >>
| >> We changed the line to the following:
| >>
| >> object dataColumn = row[column];
| >>
| >> This increased the performance by more than a factor of
| >> 25. Why did this happen? Is the performance hit in using
| >> ItemArray documented anywhere?
| >
| >Excelent observation. And proves that you should always
| profile your code.
| >
| >I don't think it's documented, but it really shouldn't
| be. Wether this
| >method is fast or slow depends on implementation details
| which can and
| >should change in future versions.
| >
| >Here's what I think is happening:
| >
| >row.ItemArray returns an array of objects. I may simply
| be a reference to
| >the objects stored in that row, but probably not. I think
| the objects are
| >really stored in columns, not in rows. Probably what
| happens is that ADO
| >creates a new array of with as many elements as the row
| has columns,
| >iterates through all the columns in that row and copies
| the column value
| >into the array. It then passes a reference to the array
| out to the
| >application, which then picks one element out of the
| array, and discards the
| >rest.
| >
| >David
| >
| >
| >
| >.
| >
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top