databaseManager.getFoundSetCount( fs ) vs fs.getSize( )

Which is better to use in which case, e.g. speed, safer?

This:

var index = 0, size = 0;
size = databaseManager.getFoundSetCount( fs );
for ( index = 1; index <= size; index++ ) {
}

or this:

var index = 0;
for ( index = 1; index <= fs.getSize( ); index++ ) {
}

Maybe I can do something like this to make it faster?:

var index = 0, size = 0;
size = fs.getSize( );
for ( index = 1; index <= size; index++ ) {
   if ( index % 150 === 0 ) {
      size = fs.getSize( );
   } 
}

The safest way to loop a foundset is to use the foundset.foreach() function, see Working with Data | Docs

This link to Gary Dotzlaw’s excellent series of tutorials should be useful:

http://dotzlaw.com/tutorials/servoy-tutorials/servoy-tutorial-optimizing-code-performance/