External Methods or Declares

I was just wondering what the more efficient method of exposing macOS class functions and properties for items that could be used a lot, eg metal rendering.

Should i create a external method:

Private Function EX_arrayLength(p as Integer) as integer

Which sets the selector etc, and is called by

[code]Public Property arrayLength as integer
Get
#if TargetMacOS then
return EX_arrayLength(me.Handle)
#endif
End Get

Set

End Set

End Property
[/code]

OR is this ok.

Public Property arrayLength as integer
Get
  #if TargetMacOS then
    soft declare function getValue lib QuartzCore selector "arrayLength" (p as integer) as integer
    return getValue(me.Handle)
  #endif
End Get

Set
  
End Set

End Property

I was wondering when external functions are resolved, on each call, or on first call, or on startup.

If i was rendering a scene as fast as possible and say the arraylength property was being got a lot on each render, which would be the best pratice for getting the values?

Just ran a test polling two different properties code the different ways and there is literally no difference in speed of hitting it 1,000,000 times. (~0.2 of a second).

External methods and declares are one and the same.

Soft declares are resolved on first use. “Hard” declares are resolved on startup.

Just wondering if there was any speed improvements to be had.
All my previous declares aren’t called very often and never in performance code.

[quote=423870:@Graham Busch]Just wondering if there was any speed improvements to be had.
All my previous declares aren’t called very often and never in performance code.[/quote]
Yes, there is. I don’t have any numbers to hand, but in my tests when “External methods” were first introduced, I discovered they are faster and I try to use them as much as possible. It makes sense as declares wrapped in a method have the overhead of the wrapping method.

In both of your tests, they’re wrapped in a method. Try comparing one that’s in a method and one that’s declared as an External Method.

For me personally, I have most of the Foundation and AppKit declares as external methods, while other functions I have as methods/properties of a NSObjectWrapper subclass. The latter is easier for functions/objects I don’t use regularly.

You are right!, i am now getting 10x speed improvements using direct calls to external method (0.2 seconds compared to 0.02)
I think i will cache the handles to the object and call the functions directly in the code which is performance based.

Wrapping all the metal classes up is very handy to figure out what is going on and get it running. Then optimizing later will be the smarter option i think. I get very confused very quickly trying to figure out what all the handles are :stuck_out_tongue: