Why is the first action 100 times faster than the second action?
First:
Second:
Although the second one functionally works, the fact that it's 100 times slower is making it difficult to use. I do lots of image processing and this code is handicapping my macros.
I'm not sure if this will be a workable solution for me. I may have to continue to ask for a native KM action that does this, in order to increase speed 100-fold.
You've got the instantiation time for the AppleScript environment for the action itself. Then the instantiation and execution time for the macro we've created with the AppleScript. That's a lot more overhead than the 1-2ms of a simple KM action.
On my old Intel the total time is ~250ms and I'd expect ~1/2 that for your Mn beast, so that tracks...
Yeah -- this a workround, not a solution. But it does show it's doable while we wait.
I also wonder if you've a chance for some refactoring, to limit Clipboard shuffling. And (heresy!) maybe look outside of KM to an imagemagick or similar processing pipeline if absolute speed is that important.
The main problem (not the only problem) with ImageMagick is that to use it effectively (ie, without exporting images to files) you need to use its APIs and a real programming language. What KM should do is create native actions that incorporate ImageMagick's APIs for use on KM's memory-based clipboards. But that's such a big project I don't even plan to ask the Architect to do that.
And I wasn't impressed with ImageMagick's speed. It took me 300 seconds to perform some basic transformations on a single screen captured file. I would find 300 milliseconds to be intolerable.
Keyboard Maestro Execute Javascript for Automation actions use a more lightweight mechanism for access to the values of KM Variable names, and the small chevron to the left of the code text field lets you pare down the number of exported variables to the minimum needed.
Whether this has a subjectively significant effect on performance I don't know,
but experiment is the only source of knowledge, and it might be worth testing.