The Wagner Blog
Development Notes, News and Trivia









Subscribe to "The Wagner Blog" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.
 

 

Wednesday, June 12, 2002
 

I call this a wholesale re-print of Sam's excellent post. And I do this primarily so that it becomes searchable on my archives.

Drew has some excellent followup to the .NET Arrays article. Sam pointed out that Dr. GUI has put up Part #6 of his .NET series: "Arrays in the .NET Framework".

He covers a lot of good stuff, but the most important thing I think he points out is how allocation differs between value types vs. reference types.

Yes, I believe that an thorough understanding of value types vs. reference types is essential to every .NET Developer.  MSDN has documented some Value Type Usage Guidelines. The ultimate explanation, IMHO, is the Richter chapter.

...it's important to note that you can actually get better perfomance by for'ing the array manually, like so:


  for(int index = 0; index < myArray.Length; index++)

  {

    object o = myArray[index];

    ...

  }

Not only does this avoid the overhead of IEnumerable and IEnumerator, but it also takes advantage of a little known Microsoft JIT trick which optimizes away bounds checking on the array. The only place I've ever seen the afforementioned JIT optmization documented is here in this article under the section titled "Use For Loops for String Iteration—version 1". From the section:

"The JIT is smart enough (in many cases) to optimize away bounds-checking and other things inside a For loop, but is prohibited from doing this on foreach walks. The end result is that in version 1, a For loop on strings is up to five times faster than using foreach. This will change in future versions, but for version 1 this is a definite way to increase performance."[Drew's Blog]

Cool! I knew about the IEnumerable and IEnumerator overhead but not the JIT trick. Thanks for the article pointer. I like these too:

  • Use simple structs when you can, and when you don't do a lot of boxing and unboxing. Tradeoffs    ValueTypes are far less flexible than Objects, and end up hurting performance if used incorrectly. You need to be very careful about when and how you use them.
  • Use StringBuilder for Complex String Manipulation

    When a string is modified, the run time will create a new string and return it, leaving the original to be garbage collected. Most of the time this is a fast and simple way to do it, but when a string is being modified repeatedly it begins to be a burden on performance: all of those allocations eventually get expensive.

    Tradeoffs   There is some overhead associated with creating a StringBuilder object, both in time and memory. On a machine with fast memory, a StringBuilder becomes worthwhile if you're doing about five operations. As a rule of thumb, I would say 10 or more string operations is a justification for the overhead on any machine, even a slower one.
  • Pick Data Reader Over Data Set When You Can

    Use a data reader whenever when you don't need to keep the data lying around. This allows a fast read of the data, which can be cached if the user desires. A reader is simply a stateless stream that allows you to read data as it arrives, and then drop it without storing it to a dataset for more navigation. The stream approach is faster and has less overhead, since you can start using data immediately. You should evaluate how often you need the same data to decide if the caching for navigation makes sense for you. Here's a small table demonstrating the difference between DataReader and DataSet on both ODBC and SQL providers when pulling data from a server (higher numbers are better):

      ADO SQL
    DataSet 801 2507
    DataReader 1083 4585

    As you can see, the highest performance is achieved when using the optimal managed provider along with a data reader. When you don't need to cache your data, using a data reader can provide you with an enormous performance boost.

[Sam Gentile's Radio Weblog]
7:48:18 PM    

.NET Framework FAQ updated today and includes us .NET Bloggers: Brad, Charles Cook, John Lam, Peter Drayton, Ingo Rammer, Drew, and Me.

Looks like they forgot Tomas Restapo, Justin Rudd, Simon Fell, Jim Murphy, Keith, Chris Kinsman, Jason Bock, Neils Berglund, Richard Caetano

That's 17, compared to only 15 reported by the Dark Side tonight-))

[Sam Gentile's Radio Weblog]
7:45:21 PM    

My comments about BMW actually caused some responses in radioland. Cool! Let me just say that I think the BMW is a good car but over-hyped. The example of the G35 was a bit drastic I know. I did that on purpose. Its an issue of value.  In my mind the BMW 330 would be a good value at 10K less than what they are charging for it. And by the way, I think I mentioned before that I have the editor of "European Car" living down the street from me and he pretty much admitted in conversation that many magazine's pander to the BMW hype because they want to sell issues. Sort of reminds me of all the mags that pander Microsoft stuff because they want to sell issues. Its a catch 22 type thing. Hype begets market share which begets more hype. Eventually someone may actually discover that the "emporer has no clothes on".
6:57:47 PM    

Doc is going to Munich for JabberConf. Hope he has a chance to check out Kloster Andechs where the monks have been brewing the best beer in Germany for the past 500 years.

Speaking of Germany. Martin has a link to a Content Mgmt App that consists of 150 line of code. Wonder what you can do in 150 lines....


6:14:40 AM    

The Register: "Java Applets for the Masses"
6:10:18 AM    

Mounting problems with the BMW 7 Series. Maybe one day people will realize how overrated the Beemer really is. Nice car for the most part but definetly much to overhyped. Don't believe me? Just test drive a 330 and a Infiniti G35 back to back. And then decide what to do with the $10K that you can save with the Infiniti G35
6:02:17 AM    


Click here to visit the Radio UserLand website. © Copyright 2004 Thomas Wagner.
Last update: 5/2/2004; 4:44:09 PM.
This theme is based on the SoundWaves (blue) Manila theme.
June 2002
Sun Mon Tue Wed Thu Fri Sat
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30            
May   Jul