4

Will registering functions in a TdwsUnit yield the same performance as regular magic functions such as those registered in the dwsMathComplexFunctions.pas unit?

FHannes
  • 783
  • 7
  • 22
  • What's a TdwsUnit? Is it a third party library? If so, ask the library vendor. I don't think your question belongs here. –  Mar 27 '13 at 06:49
  • @RawN TdwsUnit is a component/class in the DWScript library – Eric Grange Mar 27 '13 at 07:36
  • 1
    @RawN If every question about third party libraries was frowned upon, SO would be a lonely and boring place indeed. – Frank Schmitt Mar 27 '13 at 09:32
  • 1
    @RawN The library is free and open source + Eric maintains it and is active here, so it's the perfect spot to find information on it or ask questions about it. This way, everyone can benefit from the answers. – FHannes Mar 27 '13 at 09:36
  • My bad. I stand corrected. –  Mar 27 '13 at 16:46

1 Answers1

2

Usually no, because TdwsUnit functions and methods's OnEval event gets the full comfortable & safe treatment:

  • call parameters are evaluated and pushed on the stack
  • a TProgramInfo/IInfo context is made accessible so you get comfortable access to variables by name, and can in turn call everything else in the script comfortably
  • your execution is protected by an exception frame

By contrast, magic functions get none of that: they just get a list of expressions for the parameters, and that's all. No stack context, no easy access to anything else, so it's up to you to evaluate the parameters and handle everything. That makes them more suitable for simple tasks that will need to happen fast.

Note that incrementally, in addition to OnEval, some functions in TdwsUnit are now getting an OnFastEval event, which is an alternate way to declare a magic function.

Eric Grange
  • 5,931
  • 1
  • 39
  • 61