I made a function in Tapestry 23x faster today by sorting an array using its indices instead of using its data directly. Like this:

let unsorted = items
var indices = Array(unsorted.indices)
indices.sort { a, b in unsorted[a].thing > unsorted[b].thing }
items = indices.map { unsorted[$0] }

This avoided a bunch of ARC noise.

I don't know all the internal details in play here, but sometimes Swift doesn't seem so.... swift.

@bigzaphod is `items` objc types?
@doctorgoktor nope, but kind of large structs.