Skip to content

Why DifferenceKit is so much faster than Apple's Foundation diffing? #140

@Moriquendi

Description

@Moriquendi

Checklist

I'm quite amazed by how fast DifferenceKit is compared to Apple's Foundation diffing.
Can someone please explain what's the catch here?

Is there any reason why Apple chooses to use slower algorithm for their collection diffing?

Here's a sample test I run to compare results:

for _ in 0..<5 {
   var source: [Item] = []
   for i in 0..<10_000 {
      source.append( Item(value: i) )
   }
            
   let target: [Item] = source.shuffled()
            
   measure(name: "DifferenceKit") {
      let _ = StagedChangeset(source: source, target: target)
   }
            
   measure(name: "Foundation") {
      let _ = target.difference(from: source)
   }
}

Output:

Time: DifferenceKit - 29.129458333500224 msec
Time: Foundation - 1961.1885833332963 msec
Time: DifferenceKit - 17.962249999982305 msec
Time: Foundation - 1882.0110833335093 msec
Time: DifferenceKit - 17.888999999740918 msec
Time: Foundation - 1904.927041666724 msec
Time: DifferenceKit - 17.906958333242073 msec
Time: Foundation - 1907.209416666774 msec
Time: DifferenceKit - 18.071041666644305 msec
Time: Foundation - 1919.3862499996612 msec

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions