Groups | Blog | Home
all groups > dotnet performance > february 2006 >

dotnet performance : Nested objects slow fetching?


sandrapacino NO[at]SPAM libero.it
2/23/2006 3:59:40 PM
I have a question which is perhaps dumb. I would like to know wheter
there is difference in performance getting a value through:

MyObj1.MyObj2.MyObj3.MyObj4.MyObj5.MyObj6.MyObj7.MyObj8.MyProperty

instead of

MyObj1.MyProperty

or it's just the same? And if there is, what are we talking about ?
(especially with VB.NET).

Thank you very much,

-s
sandrapacino NO[at]SPAM libero.it
2/26/2006 8:33:22 PM
Thank you Robbe !!

I was just out of curiosity because a colleague of mine is claiming
that each "." requires an additional computation (to compute the new
address). So wanted to double check with you experts !

By the way, always on the same subject. When I use:

with Object
.Nested1 = Something
.Nested2 = Something
.Nested3 = Something
.Nested4 = Something
end with

is more efficient than:

Object.Nested1 = Something
Object.Nested2 = Something
Object.Nested3 = Something
Object.Nested4 = Something

or just the same?

I have a "suspect" that the first one could be somehow faster, because
I noticed the compiler treats
"with Object" as a *real* instruction (can place a breakpoint for
instance) and not just as a handy shortcut...

Thank you for your kind explanation !

-Sandra
Robbe Morris [C# MVP]
2/26/2006 9:56:38 PM
Shouldn't be any difference. An object is an object.
The runtime start up of the first instance of that class
"might" be minutely slower due to overhead of
inheritance with that many classes. I doubt it would be enough to bother
discussing if at all.



--
Robbe Morris - 2004-2006 Microsoft MVP C#
http://www.eggheadcafe.com/forums/merit.asp





[quoted text, click to view]

Daniel O'Connell [C# MVP]
2/26/2006 10:49:17 PM

[quoted text, click to view]

Well, each . is going to require some extra work. Properties are going to
have to be called, memory indirections are going to occur, yes. As to
whether it is an important concern with performane is another matter. It
likely won't be any where near as damaging as, say, one database connection.

[quoted text, click to view]

In that circumstance...maybe. Is "Object" a property or is it a local
variable? If it is a property, especially one that does alot of work, the
with method may well be faster, if it is a local variable it won't matter at
all.

AddThis Social Bookmark Button