[stdlib] Switch to a linear-space variant of Myers diffing (#83212)

This changes the implementation for `Collection.difference(from:)` to
use a linear-space complexity variation of the same Myers algorithm. The
new version is similar in execution time to the existing one, but should
alleviate memory pressure when diffing collections where the number of
differences approaches the size of the collection. While the new
algorithm returns a set of changes that is the same size as the previous
version, the specific changes are not guaranteed to be the same.

rdar://155829876
This commit is contained in:
Nate Cook
2025-09-19 12:03:26 -05:00
committed by GitHub
parent 3e981b7d8f
commit 80f052e251
2 changed files with 401 additions and 143 deletions

View File

@@ -52,12 +52,12 @@ public let benchmarks = [
BenchmarkInfo(
name: "Diffing.Large.Similar",
runFunction: { diff($0, from: bigUnabridgedLorem, to: bigLoremIpsum) },
tags: t,
tags: t + [.skip],
setUpFunction: { blackHole((bigUnabridgedLorem, bigLoremIpsum)) }),
BenchmarkInfo(
name: "Diffing.Large.Disparate",
runFunction: { diff($0, from: bigNumbersAndSymbols, to: bigAlphabets) },
tags: t,
tags: t + [.skip],
setUpFunction: { blackHole((bigNumbersAndSymbols, bigAlphabets)) }),
]