Agent profiling is not new in Domino, but it’s something that gets little press. Because it’s only available for agents, it’s probably also going to become less useful as more and more development is done in XPages. But, working from the premise that the methods in use in LotusScript do the same work on the whole as their Java counterparts, best practices learned from LotusScript are equally applicable to XPages development.
Over the last year there have been countless articles about the performance of NotesViewNavigator compared to NotesViewEntryCollections or NotesDocumentCollections. Innocently (or should that be naively), yesterday I wrote some code that got a NotesViewNavigator using CreateViewNavFromCategory and, to check the navigator had content, called NotesViewNavigator.Count. The code looked like this.
After completing the agent I ran it with profiling turned on. I’m late to the party in that I don’t usually enable this. But my first use has converted me. For the uninitiated, this setting creates a single profile document, updated after each run of the agent. It shows the amount of calls to various methods and the time each took. This was the outcome of the first run.
The agent took 58 seconds, not unacceptable, but the largest hit was from NotesViewNavigator.Count. Called the same number of times as CreateViewNavFromCategory it took about 18 times longer per call. Five minutes later I had made the following minor amendment to the code, to get the first entry from the NotesViewNavigator and check it was not ‘Nothing’ – if there are no entries for the NotesViewNavigator GetFirst still runs.