My one app’s main class was over 2500 lines so I had to cut some functions and put them into a different class file that is called to do some things like text replacements or conversions etc. I also made some of them into Cocoa classes, just because I can and I like Cocoa a lot. I think some things are faster too.
My question is- what kind of performance overhead is incurred with doing this? And would it at all be better to have all classes be Cocoa or all be ASOC? And or not class methods but instances?
I put a class ref at the start of my main script:
property CocoaHelpers : class “CocoaHelpers”
property Helpers : class “Helpers”
and then later I call on them to do things:
Helpers’s setPhotoshopPrefs_(null)
or
set fileNameList to CocoaHelpers’s textToListShell_(shellOutput) as list
I’m not seeing any performance hit (at least not a large one). But instead of calling a class method for these things, I could turn them into an instance that gets fired up on startup and call the method of each instance. Would that somehow reduce the number of times a class object is instantiated/called/dealloc’d? Would an instance make anything faster or reduce memory usage or reduce memory shuffling around?
Obviously Cocoa classes are going to be faster, but for a lot of things the difference is not worth worrying about. Mixing Objective-C and AS classes isn’t a problem because the AS classes are a bit of fiction anyway – ASObjC just uses them as a template for Objective-C classes that happen to call bits of AS code.
Organize your project in the way that makes it easiest to maintain. If you find a section is too slow, think about optimising that section then – not before.
First of all ASOC class is a plugin in your application written in AppleScript. So ASOC is always slower when it comes to pure usage of cocoa classes compared to the same class written in Objective-C. So your question about overhead I don’t understand because the more you write in Objective-C, the less overhead you have.
I remember posting a benchmark about Objective-C, AppleScriptObjC and pure AppleScript. The results were that some things are way better in pure AppleScript, others in AppleScriptObjC but it was fascinating how Objective-C out-perfom both like they run on a 20 year old machine. When it seems that there is no performance difference, repeat the task 100,000 times and you’ll notice the difference.
Remember that even when you write an AppleScriptObjC application your application’s core is still an ObjC runtime environment that is running and that your application is still Objective-C. It is the framework that is added to your application that allows you to write a plugins written in AppleScript named AppleScriptObjC
The topic wasn’t about C or assembly :D… you can’t mix pure C with ASOC so in my opinion useless to benchmark.
lol and true in in most cases (script level) but in the past I have made utilities that needs to do repetitive tasks (thinking about millions)… then saving 0.00001s for instance can make a huge difference.
OK thanks for the discussion about that. I just wanted to make sure I wasn’t causing far too much overhead in my apps. And nothing that I am doing is so repetitive (over 1000 iterations) that I really need to uber-optimize for speed.