Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comparison with Swift's CollectionDifference (SE-0240) #52

Open
lstomberg opened this issue Jan 31, 2019 · 10 comments
Open

Comparison with Swift's CollectionDifference (SE-0240) #52

lstomberg opened this issue Jan 31, 2019 · 10 comments
Assignees
Labels

Comments

@lstomberg
Copy link

How does this compare with the Swift development proposal that plans to add Ordered Collection Diffing? Are you involved with that project in any way?

https://github.com/apple/swift-evolution/blob/master/proposals/0240-ordered-collection-diffing.md

@tonyarnold tonyarnold self-assigned this Feb 1, 2019
@tonyarnold
Copy link
Owner

tonyarnold commented Feb 1, 2019

At this stage, it's a little hard to tell. Differ's more geared toward providing UI conveniences such as moves alongside a specific difference algorithm, whereas CollectionDifference provides only insertions and removals, and will potentially provide more than one underlying method of calculating differences. See @numist's comments below.

In short, I'd expect once it's released that with a couple of extension methods, CollectionDifference should become the go-to. I'll keep maintaining Differ for the foreseeable future, but I expect that the Swift-provided method will be what I personally use once it's available.

@numist
Copy link

numist commented May 13, 2019

The associatedWith: portion of the CollectionDifference.Change type exists to support the encoding of move operations and is set by inferringMoves() :)

@tonyarnold
Copy link
Owner

That's super exciting, and I'm looking forward to using it in production - thanks for your work on the proposal and implementation, Scott!

@numist
Copy link

numist commented May 14, 2019

It has been my pleasure; thanks to you for being the tip of the spear!

@tonyarnold tonyarnold pinned this issue Mar 13, 2022
@tonyarnold tonyarnold changed the title Comparison with Swift Proposal SE-0240 Comparison with Swift's CollectionDifference (SE-0240) Mar 13, 2022
@DivineDominion
Copy link

DivineDominion commented Dec 4, 2022

I was interested in this as well and ran a couple of benchmarks from https://github.com/tonyarnold/DiffPerformanceSuite -- Differ is too slow for String comparisons, so I left these out here (1x diff would take 45s on my computer).

Dwifft<Array<Character>> Differ<String> Differ<Array<Character>> Swift<String> Swift<Array<Character>>
same 0.4334 N/A 0.0094 0.0035 0.0001
created 0.0014 N/A 0.0086 0.0823 0.0808
deleted 0.0014 N/A 0.0092 0.0807 0.0793
diff 0.4843 N/A 0.0528 0.0083 0.0048

IMHO this package is a good choice when you don't compare strings and want to support older OS's 👍

@tonyarnold
Copy link
Owner

Thanks for the thorough pass at the benchmarks, and for updating them, Christian!

I wonder what it is about Differ's handling of String that is tanking performance? I have less and less need for this library, but it wouldn't hurt to fix the issues.

@tonyarnold
Copy link
Owner

Oooo, interesting - it looks like accessing a character within a String is triggering some really heavy calls into CFStringCheckAndGetCharacterAtIndex - it looks like maybe the index type is under scrutiny:

CleanShot 2022-12-05 at 22 39 47@2x

@tonyarnold
Copy link
Owner

Oh, right - Differ is assuming that String.Index == Int in a bunch of places.

@DivineDominion
Copy link

Might be because the lib predates String.Index being a proper type? 🤔

It also doesn't help that the algorithm uses Shlemiel the painter's algorithm: Glancing over the implementation, it should be possible to cache previous array indexes and advance from there, instead of computing the index from startIndex every time.

I was also considering to add a NSString variant because of it's NSRange and UTF-16 based rather stable and useful index.

@tonyarnold
Copy link
Owner

Christian, if you have the time and inclination to improve the performance of string diffing I would be mighty appreciative. I'm not actively using Differ in many places right now, so I can't justify fixing it until I find some mythical "free time" ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants