« 7 Monate bis zur Deut… | Home | Neues MBS FileMaker P… »

Boolean Variant Optimization in Xojo

Did you know that Xojo runtime optimizes boolean variants?

Variants are used a lot with Dictionaries, Introspection and as RowTag/CellTag/ColumnTag in Listbox. They need to be fast.

Take an example code like this:

Dim ObjectCountBefore As Integer = runtime.ObjectCount Dim v1 As Variant = True Dim v2 As Variant = False Dim v3 As Variant = True Dim v4 As Variant = False Dim v5 As Variant = True Dim v6 As Variant = False Dim ObjectCountAfter As Integer = runtime.ObjectCount Dim difference As Integer = ObjectCountBefore - ObjectCountAfter MsgBox Str(difference)

We check object count, create six local variables of type variant with assigning boolean values. Then we check object count again. What difference do you expect?

You may expect six, but the Xojo runtime actually optimizes this and returns the same two variants again and again. Beside the first two boolean variants created, there is no more memory used for variants. Think about that, when storing booleans in a dictionary or as a RowTag.

Even better would be if functions like the one used to create a boolean variant would be annotated, so LLVM could optimize away the calls above with the unused variables and give a difference of zero.

17 11 20 - 08:05