-
Notifications
You must be signed in to change notification settings - Fork 246
#883 regressed performance by ~7% #894
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
Comments
Synced to Apple’s issue tracker as rdar://141233035 |
Changing the code to: let lines = text.count { $0 == "\n" }
lineNumber += lines
guard lines > 1, let range = text.range(of: "\n", options: .backwards) else {
// Handle case where no newline exists
column += text.count
return
}
let lastLine = text[range.upperBound...]
column = lastLine.count Lowers the instructions executed to: 68378386615 |
After playing around in Godbolt it seems that let lines = text.count { $0 == "\n" }
lineNumber += lines
guard lines > 1, let lastNewlineIndex = text.lastIndex(of: "\n") else {
// Handle case where no newline exists
column += text.count
return
}
let lastLine = text[text.index(after: lastNewlineIndex)...]
column = lastLine.count Further lowers the instruction executed count to: 68259258073 That's only about ~ 1.5% difference from before the changes. |
macshome
added a commit
to macshome/swift-format
that referenced
this issue
Dec 13, 2024
Worked to get the perfomance to be closer to where we were before the changes in swiftlang#883. This code should be only about 1.5% slower rather than 7% slower.
macshome
added a commit
to macshome/swift-format
that referenced
this issue
Dec 17, 2024
…yPrinter for swiftlang#894 Worked to get the perfomance to be closer to where we were before the changes in swiftlang#883. This code should be only about 1.5% slower rather than 7% slower. Using a lazy filter as `count(where:_)` isn't avaliable < Swift 6.0
macshome
added a commit
to macshome/swift-format
that referenced
this issue
Dec 17, 2024
…mance Optimized the PrettyPrinter for swiftlang#894 Worked to get the perfomance to be closer to where we were before the changes in swiftlang#883. This code should be only about 1.5% slower rather than 7% slower. Using a lazy filter as `count(where:_)` isn't avaliable < Swift 6.0. Evaluating the text in reverse to shave a few more instructions off.
macshome
added a commit
to macshome/swift-format
that referenced
this issue
Dec 18, 2024
…mance PrettyPrinterPerformance Optimized the PrettyPrinter for swiftlang#894 Worked to get the perfomance to be closer to where we were before the changes in swiftlang#883. This code should be only about 1.5% slower rather than 7% slower. Using a lazy filter as `count(where:_)` isn't avaliable < Swift 6.0. One forward loop and using the UTF8 view makes this faster than the original code pre-swiftlang#883.
ahoppen
added a commit
that referenced
this issue
Dec 19, 2024
PrettyPrinterPerformance Optimized the PrettyPrinter for #894
bnbarham
added a commit
that referenced
this issue
Dec 20, 2024
bnbarham
added a commit
that referenced
this issue
Dec 20, 2024
bnbarham
added a commit
that referenced
this issue
Dec 20, 2024
…mance Revert "PrettyPrinterPerformance Optimized the PrettyPrinter for #894"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
#883 regressed swift-format’s performance by 7-8%. To reproduce run
And compare the instruction count between swift-format with and without #883.
The text was updated successfully, but these errors were encountered: