-
Notifications
You must be signed in to change notification settings - Fork 2
Fix TextDiff layout parity and add performance baselines #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
65d51d9
initial fix
iSapozhnik 4ddfa2c
refactor: improve text measurement accuracy with line prefix
iSapozhnik 3a15063
`feat: add performance test baselines for TextDiffTests`
iSapozhnik 915b24d
refactor: optimize text measurement and layout
iSapozhnik 9229e37
refactor: update text size and punctuation in previews
iSapozhnik 6ad1c5b
test: add performance and improve snapshot testing
iSapozhnik ca10965
Merge branch 'main' into bugfix/width-and-height-diff
iSapozhnik 214d5eb
todo comment
iSapozhnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...hareddata/xcbaselines/TextDiffTests.xcbaseline/BF20AB95-BD61-4DE5-BFD2-9B7DB182F4A1.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>classNames</key> | ||
| <dict> | ||
| <key>DiffLayouterPerformanceTests</key> | ||
| <dict> | ||
| <key>testLayoutPerformance1000Words()</key> | ||
| <dict> | ||
| <key>com.apple.dt.XCTMetric_Clock.time.monotonic</key> | ||
| <dict> | ||
| <key>baselineAverage</key> | ||
| <real>0.058013</real> | ||
| <key>baselineIntegrationDisplayName</key> | ||
| <string>Local Baseline</string> | ||
| </dict> | ||
| </dict> | ||
| <key>testLayoutPerformance200Words()</key> | ||
| <dict> | ||
| <key>com.apple.dt.XCTMetric_Clock.time.monotonic</key> | ||
| <dict> | ||
| <key>baselineAverage</key> | ||
| <real>0.013204</real> | ||
| <key>baselineIntegrationDisplayName</key> | ||
| <string>Local Baseline</string> | ||
| </dict> | ||
| </dict> | ||
| <key>testLayoutPerformance500Words()</key> | ||
| <dict> | ||
| <key>com.apple.dt.XCTMetric_Clock.time.monotonic</key> | ||
| <dict> | ||
| <key>baselineAverage</key> | ||
| <real>0.027967</real> | ||
| <key>baselineIntegrationDisplayName</key> | ||
| <string>Local Baseline</string> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
33 changes: 33 additions & 0 deletions
33
.swiftpm/xcode/xcshareddata/xcbaselines/TextDiffTests.xcbaseline/Info.plist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>runDestinationsByUUID</key> | ||
| <dict> | ||
| <key>BF20AB95-BD61-4DE5-BFD2-9B7DB182F4A1</key> | ||
| <dict> | ||
| <key>localComputer</key> | ||
| <dict> | ||
| <key>busSpeedInMHz</key> | ||
| <integer>0</integer> | ||
| <key>cpuCount</key> | ||
| <integer>1</integer> | ||
| <key>cpuKind</key> | ||
| <string>Apple M1</string> | ||
| <key>cpuSpeedInMHz</key> | ||
| <integer>0</integer> | ||
| <key>logicalCPUCoresPerPackage</key> | ||
| <integer>8</integer> | ||
| <key>modelCode</key> | ||
| <string>MacBookPro17,1</string> | ||
| <key>physicalCPUCoresPerPackage</key> | ||
| <integer>8</integer> | ||
| <key>platformIdentifier</key> | ||
| <string>com.apple.platform.macosx</string> | ||
| </dict> | ||
| <key>targetArchitecture</key> | ||
| <string>arm64</string> | ||
| </dict> | ||
| </dict> | ||
| </dict> | ||
| </plist> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| import AppKit | ||
| import XCTest | ||
| @testable import TextDiff | ||
|
|
||
| // swift test --filter DiffLayouterPerformanceTests 2>&1 | xcsift | ||
|
|
||
| final class DiffLayouterPerformanceTests: XCTestCase { | ||
| func testLayoutPerformance200Words() { | ||
| runLayoutPerformanceTest(wordCount: 200) | ||
| } | ||
|
|
||
| func testLayoutPerformance500Words() { | ||
| runLayoutPerformanceTest(wordCount: 500) | ||
| } | ||
|
|
||
| func testLayoutPerformance1000Words() { | ||
| runLayoutPerformanceTest(wordCount: 1000) | ||
| } | ||
|
|
||
| private func runLayoutPerformanceTest(wordCount: Int) { | ||
| let style = TextDiffStyle.default | ||
| let verticalInset = DiffTextLayoutMetrics.verticalTextInset(for: style) | ||
| let contentInsets = NSEdgeInsets(top: verticalInset, left: 0, bottom: verticalInset, right: 0) | ||
| let availableWidth: CGFloat = 520 | ||
|
|
||
| let original = Self.largeText(wordCount: wordCount) | ||
| let updated = Self.replacingLastWord(in: original) | ||
| let segments = TextDiffEngine.diff(original: original, updated: updated, mode: .character) | ||
|
|
||
| measure(metrics: [XCTClockMetric()]) { | ||
| let layout = DiffTokenLayouter.layout( | ||
| segments: segments, | ||
| style: style, | ||
| availableWidth: availableWidth, | ||
| contentInsets: contentInsets | ||
| ) | ||
| XCTAssertFalse(layout.runs.isEmpty) | ||
| } | ||
| } | ||
|
|
||
| private static func largeText(wordCount: Int) -> String { | ||
| let vocabulary = [ | ||
| "alpha", "beta", "gamma", "delta", "epsilon", "theta", "lambda", "sigma", | ||
| "swift", "layout", "render", "token", "word", "segment", "measure", "width" | ||
| ] | ||
| var words: [String] = [] | ||
| words.reserveCapacity(wordCount) | ||
|
|
||
| for index in 0..<wordCount { | ||
| words.append(vocabulary[index % vocabulary.count]) | ||
| } | ||
|
|
||
| return words.joined(separator: " ") | ||
| } | ||
|
|
||
| private static func replacingLastWord(in text: String) -> String { | ||
| guard let lastSpace = text.lastIndex(of: " ") else { | ||
| return "changed" | ||
| } | ||
| return String(text[..<lastSpace]) + " changed" | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.