- DelphiTools - https://www.delphitools.info -

Refactoring DWScript dynamic arrays

After reaching initial stages of the x86-64 JIT [1], work on a long overdue enhancement of the DWScript engine has started: refactoring how dynamic arrays are implemented.

One of the goals when the 32bit JIT was introduced [2] was to edge out the Delphi 32bits compiler, which was not too complicated as Delphi was using the FPU, so merely using SSE2 at the time was enough. But the Delphi 64bits compiler makes good use of SSE2, so the only way to edge it out would be to leverage AVX2 and vectorisation.

Variant Dynamic Arrays

However, DWScript internals are historically using the Variant type everywhere. Low-level bypasses are used in cases when the script-side type is strongly-typed, which eliminates the Variant overhead in many cases. This is and was very convenient, but became more and more limiting:

While it would eventually be nice to no longer rely on the Variant type everywhere, that would require a significant amount of work, and the Variant is mostly a bottleneck for arrays.

So what’s happening ?

The idea is that ultimately the JITted code could run way faster with much less memory. Non-JITted code on the other hand may experience lower performance. This would especially be the case for scripts that do not rely on strongly-typed types.