TdwsUnit Performance

Registering functions in TdwsUnit gives the same performance as regular magic functions, such as registered in the dwsMathComplexFunctions.pas module?

+4
source share
1 answer

Usually not, because the functions and methods of TdwsUnit. The OnEval event receives a complete convenient and safe treatment:

  • call parameters are evaluated and pushed onto the stack
  • the TProgramInfo / IInfo context becomes accessible, so that you get convenient access to variables by name and you can, in turn, calmly name everything else in the script
  • your execution is protected by an exception frame

On the contrary, magic functions do not receive anything: they simply receive a list of expressions for parameters and that’s all. There is no stack context, no easy access to everything else, so you need to evaluate the parameters and process everything. This makes them more suitable for simple tasks that need to be completed quickly.

Note that gradually, in addition to OnEval, some functions in TdwsUnit now receive the OnFastEval event, which is an alternative way to declare a magic function.

+2
source

All Articles