Under Swift 6 on Sequoia, why is ContiguousArray suddenly so slow to allocate

I generate images with command line apps in Swift on MacOS. Under the prior Xcode/MacOS my code had been running at the same performance for years. Converting to Swift 6 (no code changes) and running on Sequoia, I noticed a massive slowdown. Running Profile, I tracked it down to allow single line:

var values = ContiguousArray<Double>(repeating: 0.0, count: localData.options.count)

count for my current test case is 4, so its allocating 4 doubles at a time, around 40,000 times in this test. This one line takes 42 seconds out of a run time of 52 seconds. With the profile shown as:

26	41.62 s   4.8%	26.00 ms	                               specialized ContiguousArray.init(_uninitializedCount:)
42	41.57 s   4.8%	42.00 ms	                                _ContiguousArrayBuffer.init(_uninitializedCount:minimumCapacity:)
40730	40.93 s   4.7%	40.73 s	                                 _swift_allocObject_
68	68.00 ms   0.0%	68.00 ms	                                  std::__1::pair<MallocTypeCacheEntry*, unsigned int> swift::ConcurrentReadableHashMap<MallocTypeCacheEntry, swift::LazyMutex>::find<unsigned int>(unsigned int const&, swift::ConcurrentReadableHashMap<MallocTypeCacheEntry, swift::LazyMutex>::IndexStorage, unsigned long, MallocTypeCacheEntry*)
7	130.00 ms   0.0%	7.00 ms	                                  swift::swift_slowAllocTyped(unsigned long, unsigned long, unsigned long long)

which is clearly inside the OS allocator somewhere. What happened? Previously this would have taken closer to 8 seconds or so for the entire run.

Switching to Array instead of ContiguousArray takes the same amount of time.

OK, more testing, I switched back to Swift 5 and then same issue exists, so the problem seems to be in the Sequoia memory allocator.

I logged in with the wrong Apple Identity but can't remove this message here.

Under Swift 6 on Sequoia, why is ContiguousArray suddenly so slow to allocate
 
 
Q