FALSE ALARM: AppleScript is enormously slow on Sonoma

EDIT: This post describes the situation correctly - however this was apparently a temporary issue on a specific machine. In the end, AppleScript runs on Sonoma just as fast as on Ventura.

It appears that AppleScript is enormously slow on Sonoma (at least on its latest beta).

A task that takes slightly less than 1 second on Ventura, takes 13 seconds on Sonoma.

That is, Sonoma is more than 13 times slower.

I only measured one task so far. I wonder if other users experience the same thing?

(I remember how happy I was when AppleScript became blazingly fast - several times faster than before - on Monterey. Hopefully Sonoma won’t bring us back to stone age when released).

EDIT: tested another totally different task - with same abysmal results.

I haven’t run into this problem at all. If anything, everything seems more stable than before. But I might be testing different areas than you.

1 Like

I am not seeing any issues. I was running some just yesterday and thought they were running more quickly.

Sample code ?

A difference that’s reproducible on other people’s systems ?

(If not, then that may free you up to look for other issues)

I reported AppleScript slowdown issue on macOS 11 + M1 Mac mini.
And it was fixed on macOS 12 as everybody know.
I didn’t install Sonoma beta yet.

I hope Sonoma Beta testers to write efficient report to Apple.

–Which machine?
I selected some sample code and compare the result of various machines.

–How measure it?
Measure each script by using Shane’s Script Geek.

–What script do you use?
On macOS 11, communication with GUI apps are not so slow, Cocoa scripting and random number generation was too slow.

So, I selected some scripts to measure execuion speed.
They are a kind of time consumer scripts. It takes a long time to execute.

And one script takes about 5 minutes to calculate the most far place from nearest station (700 points x 8,000 stations).

use AppleScript version "2.4"
use scripting additions
use framework "Foundation"

script spdPerm
	property permutations : missing value
end script

on run
	--Test by MacBook Pro 2012 Retina Core i7 2.6GHz
	--set theList to {"A", "T", "G", "C"} --0.01 secs (4 digits) 24 items.
	--set theList to {"A", "T", "G", "C", "1"} --0.05 secs (5 digits) 120 items.
	--set theList to {"A", "T", "G", "C", "1", "2"} --0.21secs (6 digits) 720 items.
	set theList to {"A", "T", "G", "C", "1", "2", "3"} --1.44 secs (7 digits) 5,040 items.
	--set theList to {"A", "T", "G", "C", "1", "2", "3", "4"} --11.54 secs (8 digits) 40,320 items.
	--set theList to {"A", "T", "G", "C", "1", "2", "3", "4", "5"} --107.27 secs (9 digits) 362,880 items.
	
	set aRes to permute(theList) of me
	return aRes
end run


on permute(theList as list)
	set theArray to current application's NSMutableArray's arrayWithArray:theList
	set (permutations of spdPerm) to current application's NSMutableArray's array()
	prmt(theArray, 0, (count theList) - 1)
	
	--Return AppleScript string list
	set aFinishArray to current application's NSMutableArray's new()
	set anEnum to (permutations of spdPerm)'s objectEnumerator()
	repeat
		set aValue to anEnum's nextObject()
		if aValue = missing value then exit repeat
		set aStr to aValue's componentsJoinedByString:""
		(aFinishArray's addObject:aStr)
	end repeat
	
	return aFinishArray as list
end permute


on prmt(theArray, theStart as number, theEnd as number)
	if (theStart = theEnd) then
		(permutations of spdPerm)'s addObject:theArray
	else
		repeat with x from theStart to theEnd
			set theCopy to theArray's mutableCopy()
			--swap
			if (x > theStart) then (theCopy's exchangeObjectAtIndex:theStart withObjectAtIndex:x)
			prmt(theCopy, theStart + 1, theEnd)
		end repeat
	end if
end prmt
use AppleScript version "2.4"
use framework "Foundation"
use framework "GameplayKit" -- requires macOS 10.12
use scripting additions

script spd
	property aList : {}
	property aRes : {}
	property bRes : {}
end script

set (aRes of spd) to {}
set (bRes of spd) to {}

--テスト用データリストの作成(30万アイテム)
set (aList of spd) to makeShuffledSequantialNumList(1, 300000) of me


--昇順ソートの時間計測
set a1Dat to current application's NSDate's timeIntervalSinceReferenceDate()

set (aRes of spd) to sort1DList_ascOrder_((aList of spd), true)

set b1Dat to current application's NSDate's timeIntervalSinceReferenceDate()

set c1Dat to b1Dat - a1Dat


--降順ソートの時間計測
set a2Dat to current application's NSDate's timeIntervalSinceReferenceDate()

set (bRes of spd) to sort1DList_ascOrder_((aList of spd), false)


set b2Dat to current application's NSDate's timeIntervalSinceReferenceDate()
set c2Dat to b2Dat - a2Dat

return {c1Dat, c2Dat}
--> {1, 1}



--1D Listをsort / ascOrderがtrueだと昇順ソート、falseだと降順ソート
on sort1DList:theList ascOrder:aBool
	set aDdesc to current application's NSSortDescriptor's sortDescriptorWithKey:"self" ascending:aBool selector:"compare:"
	set theArray to current application's NSArray's arrayWithArray:theList
	return (theArray's sortedArrayUsingDescriptors:{aDdesc}) as list
end sort1DList:ascOrder:


on makeShuffledSequantialNumList(fromNum, toNum)
	script spdL
		property nList : {}
	end script
	
	set (nList of spdL) to {}
	
	repeat with i from fromNum to toNum by 1
		set the end of (nList of spdL) to i
	end repeat
	
	set anArray to current application's NSArray's arrayWithArray:(nList of spdL)
	set newArray to anArray's shuffledArray() as list -- requires macOS 10.12
	
	return newArray
end makeShuffledSequantialNumList
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

repeat 10000 times
	random number from 1 to 99999999
end repeat

Yes, I remember that you played a significant role in helping dramatically improving AppleScript speed in macOS 12 Monterey (Shane let us know about your involvement back then).

Now, when it comes to AppleScriptObjC, Sonoma brings us back to pre-Monterey days (and, possibly, worse). That’s at least my experience. I’ll post some evidence soon.

No sample code. The slowness I’m witnessing affects complex AppleScriptObjC scripts (I don’t know if it affects the standard AppleScript).

The issue is consistently reproducible on the same machine running Ventura and Sonoma on different partitions.

My AppleScriptObjC tools scan multitude of images (either images on disk or links in InDesign documents).

Here’s one such app - it scans folders of images and vector graphics files:

https://zevrix.com/downloads/GraphicInspector.dmg

(It’s a commercial app. I can give a free NFR license to any forum member who’s interested - just contact me privately if it doesn’t violate forum policies).

To test, drop a folder of images (or any files for that matter) on the app. All processing is done by an AppleScriptObjC script.

Scanning the same folder of images takes less then 2 seconds on Ventura - and 12 seconds on Sonoma.

I’m experiencing even worse results with tools that scan images in InDesign files.

I’m afraid of InDesign’s slowdown on Sonoma.

EDIT: This turned to be a temporary issue, this info can be ignored.

Like I mentioned, the scripts that don’t involve InDesign are also dramatically slower. From what I’m witnessing, it’s AppleScriptObjC itself that’s much slower.

1 Like

Tried dragging a folder of 400 images of various formats (328 MB in total, including one 59 MB file) onto Graphic Inspector.app and it took 6.23 seconds. Not sure if this is the expected speed or not. Doing one or a few images at a time happens near-instantly.

The scripts @Piyomaru provided all run reasonably quickly – all except the GameplayKit one ran near-instantly, while the GameplayKit one finished in 8 seconds.

What speeds are you seeing in similar conditions?

Thanks for trying, Stephen.

Well. I have additional news now.

Before replying to you, I went to my laptop with Sonoma and ran the same tasks again. This time the scripts ran just as fast as on Ventura.

Whatever the reason for this I guess the issue is closed.

I posted my original message after running multiple tests booting back in forth in Ventura and Sonoma several times. The slowness was reproducible every time.

Now, out of the blue, all is fine. Don’t have an explanation for this - but can’t complain after all.

The results you report also look pretty fast.

@ComplexPoint also brought up important point: I certainly had to collect some info from testing on other machines first. I guess my particular MBP M1 was acting up on Sonoma partition for some time for unknown reasons.

It took 0.54 sec on M1 Mac mini+macOS 13.6.

What is the AppleScript version on macOS 14? 2.8?

2.8

Thank you. I found it in Sonoma in another partition.
I checked some un-recovered bugs and found them fixed.
The most time-consuming script (700 x 8,000 distance calc) worked a little faster than macOS 13.x.

A list shuffler script using GameplayKit worked in 9.73 sec for 300000 items.
Ventura took 0.54 sec. This may be a GameplayKit issue.

I have to correct my post.

300,000 item array randomize and ascending/descending sort test result is here on my M1 Mac mini.

macOS 13.6:
ascending:0.5 sec
descending:0.5 sec
total: 10.13 sec (data generation → sort x2 direction)

macOS 14 RC:
ascending:0.48 sec
descending:0.48 sec
total: 9.73 sec (data generation → sort x2 direction)

My time eater benchmark result is here.

700 places x 8,000 places distance calculation (Get each nearest train/bus station)

macOS 13.6:
1 min 45 sec

macOS 14 RC:
1 min 35 sec

Well, after all it maybe not a completely false alarm…

I just did some work on macOS 14.2 beta for a few hours. At first, AppleScript was consistently slow across several apps. Rebooted the Mac - still slow.

Rebooted again - now AppleScript is blazingly fast, as expected.

Another reboot - AppleScript stays fast.

So who the hell knows what it all means. All I know is that I witnessed this slowness on Sonoma several times already.

1 Like

I’m using Sonoma 14.2, and Script Debugger is not working at all. When it comes up, I cannot type into the new window.

It doesn’t seem to have anything to do with the issue I posted originally. You may want to post it as a separate topic and describe exactly the issue you experience, step by step.