« Fragile UI? Don’t do it “on my behalf!” | Main| Show Time »

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.

Teamstudio Profiler screenshot

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    

Comments

1 - My recollection (from Bob Balaban's book on Java in 4.6) is that in sorted collections, GetNth is fast; but in unsorted collections GetNth is slow. The question is: which type of collection is John getting?

2 - In this case, John was using db.AllDocuments, so it was unsorted. The discusion we ended up having around this was that it is easy to get mislead into thinking there is an easy fix by just swapping out the 'slow' call and replace it with the 'fast' one. In the end there is no such thing as the 'fast' one for all conditions, even though most people will tell you otherwise.

3 - If you have the luxury of using a view that contains column data with the values you are after, would using the NotesViewEntry column values be more efficient than accessing the document fields?

4 - @3 - YES, much faster, because it doesn't have to open the note. You can also use NotesDocument.ColumnValues to access the values cached in the view index. Highly recommended.

Post A Comment

Feeds

Custom Button Custom Button

Category Cloud

Disclaimer

The views expressed by the authors on this blog do not necessarily reflect the views of Teamstudio, those who link to this blog, or even the author’s mother, father, sister, brother, uncle, aunt, grandparents, cousins, step relations, any other blood relative - and sometimes not even the author himself or herself.

Comments on this website are the sole responsibility of their writers and it is assumed those writers will take full responsibility, liability, and blame for any libel or litigation that results from something written in, or as a direct result of something written in, a comment. The accuracy, completeness, veracity, honesty, exactitude, factuality and politeness of comments are not guaranteed. Oh, how they are SO not guaranteed.
en-us,en;q=0.5OFFCCBot/1.0 (+http://www.commoncrawl.org/bot.html)38.107.191.89getthemostfromnotes.comHTTP/1.180Lotus-Domino/tsblog.nsf/d6plinks/GetNthDocument_GetNextDocument_TimeDifferences