3 ms·
If you're saying 1000x for Swift, my immediate guess is you've got some pathological code that is triggering a massive number of copies of CoW structures (e.g.
by eridius 10y ago
If you're saying 1000x for Swift, my immediate guess is you've got some pathological code that is triggering a massive number of copies of CoW structures (e.g. arrays, dictionaries, sets).
- mpweiher 10y agoI am pretty sure it wasn't, and I wasn't trying to construct a case either. I haven't run into the CoW issues myself yet, though with that I am actually curious enough to try to construct a case.
- eridius 10y agoWhy are you pretty sure it wasn't? Swift is usually pretty efficient. Massive numbers of CoWs is by far the most likely culprit for any kind of huge slowdown. And without actually profiling it, it's hard to detect when CoWs are happening, you mostly just have to be aware of when you're writing code that keeps multiple references to a CoW data structure that you're mutating. It's very common to get single accidental CoW copies. Getting a large number of them tends to require slightly odder code. For example, saying something like `col.reduce([], { $0 + $1.elements })`, which is a normal idiom for Haskell, will introduce a CoW copy on the accumulator array at every single step. And this is true even if you modify it to something like `col.reduce([], { var ary = $0; ary.append(contentsOf: $1.elements); return ary })`, because behind the scenes the reduce method will still have a reference to the accumulator while the closure is executing.