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
Add missing final keyword #22
Conversation
👍 I don't see anything wrong with adding explicit E.g., is it only to make things explicit (like the way this codebase tends to spell out |
@swift-ci test |
@lorentey yes, sure.
|
@DimaMishchenko do you have a way to quantify the performance optimization? E.g., does it show up in benchmarks? Have you seen a codegen improvement? |
I think it makes sense to make public types final if they aren't intended to be subclassed. It's my understanding that Swift will "infer" the final when possible, for example on any non-public classes that don't have subclasses (at least if you build with WMO on). Edit: @lorentey points out to me these types aren't open so they can't be subclasses outside of the module anyway. |
@lorentey first of all, sorry for long feedback. What @kylemacomber said should be correct (at least according to this and this). Which should mean that changes are only useful form code-style perspective. But I did some additional performance testing for First, simply tested func testAppend() {
var deque = Deque<Int>()
let options = XCTMeasureOptions()
options.iterationCount = 100
measure {
(0...1000000).forEach { _ in deque.append(1) }
}
} Results:
Then, benchmark test Difference is quite small (and can be just accuracy error). So @lorentey if you think that this PR is unnecessary, please feel free to close it 😀 |
On the side of adding the FWIW I recently had an unrelated disagreement at work, which was resolved through examples from swift-algorithms. One of the many things I appreciate from the Swift community is that people are largely onboard with one set of best practices. |
The recommendation in OptimizationTips is mostly out of date. It was added in 2015, predating Swift 3's introduction of the |
final
keywordMutableCollectionTests
class nameChecklist