-
Notifications
You must be signed in to change notification settings - Fork 195
attributed string fast path equality performance improvements #1415
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
base: main
Are you sure you want to change the base?
attributed string fast path equality performance improvements #1415
Conversation
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating this and for including the benchmark results! Indeed this change seems sensible especially since AttributedSubstring
already does this. I'm curious to know exactly what work we're eliding here - I suspect it's the creation and comparison of a RangeSet
representing the full range of the string when we create the AttributedString.Runs
instances to compare. Out of curiosity, did you profile the call before/after to see what calls were previously taking up the most time in the identical case?
I did not do much profiling outside of running benchmarks. But skipping all the work in the |
@jmschonfeld I think we fixed the Windows issue in #1416. Do I have to merge |
I believe CI checks out the merge commit rather than your branch, so I think re-running should be sufficient - let me try re-running it and if it fails again we can rebase/merge main in |
@swift-ci please test Windows platform |
@jmschonfeld I think this looks good to merge. Thanks! |
Thanks! Yep this looks good to me - I'll get this merged soon once we finish sorting out a few other action items for the 6.2 release |
Here is a small performance improvement to value-equality checking in
AttributedString
.When two
AttributedString
instances are identical we can returntrue
in constant-time: we do not need to check through all N characters.Currently the check for identity equality lives inside
Guts
.123 This is still constant-time… but we have the potential to move this check up sooner: directly in the==
operator onAttributedString
. This will look similar to what we already have in place forAttributedSubstring
.4Benchmarks show improvements close to two orders of magnitude increased throughput when our
AttributedString
instances are identical.Control: Equality Unique
Test: Equality Unique
Control: Equality Shared
Test: Equality Shared
Footnotes
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L77 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L84-L86 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedString%2BGuts.swift#L105 ↩
https://github.com/swiftlang/swift-foundation/blob/swift-6.1.2-RELEASE/Sources/FoundationEssentials/AttributedString/AttributedSubstring.swift#L79-L81 ↩