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
OR is this ok.
Public Property arrayLength as integer
#if TargetMacOS then
soft declare function getValue lib QuartzCore selector "arrayLength" (p as integer) as integer
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?
[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