The Right Notes

Contributing development ideas to the Lotus Domino community

Formula Language vs Lotusscript

Posted by therightnotes on February 15, 2007

Like a lot of developers, I tend to you formula language for simple task and Lotusscript for more complicated tasks. I always figured that–at least for simple items–formula language was optimized and thus faster.

Yesterday, though, my tester commented that a particular action–a typical bulk approval–seemed to be running more slowly at one level than at the previous level. The previous level had a fair amount of logic and new field creation, so that agent was written in Lotusscript. This final approval was very simple, and so I had written an agent like the following in formula language:

FIELD AppDate:=@now;
FIELD Approver:=@name([cn];@username);
FIELD Status:=”Approved”;
select @all;

The agent ran on selected documents. Since it was slow, I quickly wrote the equivalent in lotusscript:


Option Public
Option Declare
%INCLUDE "lsconst.lss"

Sub Initialize
   Dim sess As New notessession
   Dim db As notesdatabase
   Dim dc As notesdocumentcollection
   Dim thisdoc As notesdocument
   Dim nextdoc As notesdocument
   Dim goodcount As Integer

   Set db = sess.currentdatabase
   Set dc = db.unprocesseddocuments
   Set thisdoc = dc.getfirstdocument

   If dc.count = 0 Then
      Messagebox "Please select at least 1 recommendation", MB_ICONStop + MB_OK, "Bulk Approval"
      Exit Sub
   End If

   Do Until thisDoc Is Nothing
      Set nextDoc=dc.GetNextDocument(thisDoc)
      With thisDoc
         .MCAppDate = Now
         .MCApp=sess.CommonUserName
         .status="Approved"
      End With
      goodcount=goodcount + 1
      Call thisdoc.Save(True, False)
      Set thisDoc=nextdoc
   Loop

   Messagebox goodcount & " compensation recommendations approved."  , MB_ICONInformation + MB_OK, "Bulk Submit"
End Sub

Sure enough, this simple Lotusscript agent ran much faster than the formula equivalent; my tester estimate 5x faster. The question is why? Is formula language simply not as fast as I thought? Is the overhead of the progress bar that automatically appears when users run a formula language agent so high that any optimization is overwhelmed? I’m not certain, but the performance upgrade is noticeable enough that I’m not likely to try to write even simple agents in formula language anymore.

One Response to “Formula Language vs Lotusscript”

  1. My guess is that you get the performance improvement by not running @Name for every document, the Lotusscript would probably be even faster if you stored the s.commonusername in a varaible rather than calculating it every time. You could probably test this by running @name a few thousand times and seeing how long it takes, same comment probably applies to @now

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <pre> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>