UnsafeBufferPointer's extension that takes MLMultiArray has been deprecated. You can get a contiguous array of a shaped array as follows.
if let shapedArrayValue = prediction.featureValue(for: "output")?.shapedArrayValue(of: Float.self) {
result = shapedArrayValue.scalars
}
As for the performance, could you use Instruments to find out the bottlenecks? You may find this video useful.
https://developer.apple.com/videos/play/wwdc2022/10027/