KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: An advanced technique to give a compiled database application a bump in speed
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: May 6, 2012

Two strong beliefs in the development community are that the database should be fast and stable. The number one way to provide a fast database is to run it compiled. One of the "givens" to ensure stability in the compiled code is to compile with the Range Checking compiler option turned on, see the image below.



A range check is a check to confirm a number is within a certain range. This is often used with arrays, as using a number outside the upper range in an array may cause the program to crash. In 4D, the interpreter automatically does a range-check when items in an array are accessed, and throws an exception if the item is out of range.

Compilers, by their nature, do not default to range checking. The assumption is that the developer has created error-free and stable code. When range checking is turned on additional verification that checks the code "in situ" and according to the state of database objects at a given moment.

To do this range checking addition code is produced, and the overhead is a reduction in the execution speed of the database.

Whereas it is not recommended compile a 4D DB with Range Checking turned off, by default the option is checked in compiler preferences, Range Checking can be turned off locally to gain some of that speed back.

Disabling range checking locally

Even when range checking has been enabled, there may be some cases where a developer prefers that it not be applied to certain parts of code that is considered to be reliable. More particularly, in the case of loops that are repeated a great number of times, and when running the compiled database on older machines, range checking can significantly slow down processing. Insofar as the developer has the certitude that the code concerned is reliable and cannot cause system errors, Range Checking can be disabled locally.

To turn off Range Checking locally, the code to be excluded must be surrounded with the special comments //%R- and //%R+. The //%R- comment disables Range Checking and //%R+ enables it again:
... //Range checking is enabled
// %R-
... //Place the code to be excluded from range checking here
// %R+
... //Range checking is enabled again for the rest of the method