Time Differences
Subtle differences….
My fellow Teamstudio-ite John K just posted about GetNth not actually being as bad as it’s reputation. But I noticed something very interesting in the screen shot of the results.
It’s something that everyone can probably encounter because it’s very subtle… The lines that are highlighted are what caught my eye. Each of the blocks of code are doing virtually the exact same thing, and could easily have been seen in the wild as an attempt to optimize that bit of code. After all we all know, and John alluded to this, that views are faster than collections. But as I looked at this I was stumped…. Why was that simple statement costing so much? Then it dawned on me….
(read more)
My fellow Teamstudio-ite John K just posted about GetNth not actually being as bad as it’s reputation. But I noticed something very interesting in the screen shot of the results.
It’s something that everyone can probably encounter because it’s very subtle… The lines that are highlighted are what caught my eye. Each of the blocks of code are doing virtually the exact same thing, and could easily have been seen in the wild as an attempt to optimize that bit of code. After all we all know, and John alluded to this, that views are faster than collections. But as I looked at this I was stumped…. Why was that simple statement costing so much? Then it dawned on me….
(read more)
The view doesn’t open the document, but the collection does! View vs collection can be very bad if you are not being careful.
In the first two instances John was using a view to get the documents and then using the document that was returned to get the form name, but since the calls are the same for collections and views, it’s easy to just swap out one for the other without having to change too much other code. In a real world scenario, the opening of the collection or view may even be done somewhere else. Here, because the view apparently doesn’t open the document like the collection does, to the first call to actually get something off the document needs to do the open.
Now in this case the overall performance of the view is probably 2x slower than the collection since the collection only opens the documents once, but here, each loop opens the all the documents. John claims that GetNth and getNext are equivalent, and he is right, but he also says he wouldn’t recode his loops, either, but I say he missed the bigger problem – what he was doing IN the loops.
This is real benefit in using a performance monitoring tool like Profiler. Sometimes you find things you were not looking for that end up being the real problem… like with everything else in life it’s always in the last place you look.
Category Performance Tips and Tricks Coding Practices Development
Comments
Posted by Richard Schwartz At 01:41:26 PM On 08/15/2008 | - Website - |
Posted by Craig Schumann At 01:48:37 PM On 08/15/2008 | - Website - |
Posted by Mike Miller At 03:07:23 PM On 08/15/2008 | - Website - |
Posted by Bob Balaban At 04:42:26 AM On 08/16/2008 | - Website - |