Thursday, July 06, 2006

LotusScript Performance Tip - Clearing the object cache

A while back I was browsing SearchDomino looking for an answer to a problem and stumbled across a posting by Andre Guirard that made a reference to using the Delete statement to remove NotesDocument objects from memory. I was intrigued, so I asked on Notes.Net and Andre responded.

The relevant code is in Andre's response, but in the interest of completeness I will repeat it here:

Dim session As New NotesSession
Dim coll As NotesDocumentCollection
Dim db As NotesDatabase
Dim docCur As NotesDocument, docNext As NotesDocument

Set db = session.CurrentDatabase
Set coll = db.UnprocessedDocuments
Set docCur = coll.GetFirstDocument

Do Until docCur Is Nothing
Call session.UpdateProcessedDoc(docCur)
Set docNext = coll.GetNextDocument(docCur)
Delete docCur ' so documents don't accumulate in cache
Set docCur = docNext

What I'm not clear on, and have not been able to test yet, is whether this also applies to Forall loops and not just GetFirst/GetNext constructs. I also don't typically use NotesViewEntryCollections, so I don't know if it applies to those, either.


  1. OK, and what is the performance gain? I know I'll stumble the first few times over the use of "Delete", thinking "Why would they want to delete the document" - only to realize that it's not doc.remove :-P

  2. In an application that looped through 180,000 documents, changed two fields, and saved the documents, adding the Delete reduced agent run time from over 30 minutes by roughly 10 minutes. It seems to help more in long-running situations. I don't know the exact under the hood reason.

  3. Delete is definitely a good thing when flipping through large collections. But don't forget about StampAll in NotesDocumentCollection and NotesViewEntryCollection (and their Java equivalents of course), if you are putting a static value or values into all of the docs in the collection. It is incredibly fast.