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

Integrate Swift Syntax in the force_cast rule #3867

Merged
merged 11 commits into from
Mar 7, 2022
Merged

Integrate Swift Syntax in the force_cast rule #3867

merged 11 commits into from
Mar 7, 2022

Conversation

jpsim
Copy link
Collaborator

@jpsim jpsim commented Mar 4, 2022

We've tried adding Swift Syntax support to SwiftLint in the past but had to turn it off in #3107 due to distribution and portability issues.

With https://github.com/keith/StaticInternalSwiftSyntaxParser it should be possible to avoid those issues by statically linking the internal Swift syntax parser so it's available no matter where users have Xcode installed on their computer.

By removing all calls to SourceKit (collecting comment commands + checking the current Swift version), there's a really significant performance improvement.

Framework Mean [ms] Min [ms] Max [ms] Relative
SourceKit 517.8 ± 8.3 505.5 531.1 6.59 ± 0.43
SwiftSyntax 78.6 ± 5.0 72.6 92.1 1.00

In practice, the SourceKit overhead will continue being there for as long as any rule being run is still looking up the SwiftLint syntax map though.

@SwiftLintBot
Copy link

SwiftLintBot commented Mar 4, 2022

1 Warning
⚠️ This PR may need tests.
12 Messages
📖 Linting Aerial with this PR took 1.04s vs 0.96s on master (8% slower)
📖 Linting Alamofire with this PR took 1.03s vs 1.0s on master (3% slower)
📖 Linting Firefox with this PR took 3.64s vs 3.58s on master (1% slower)
📖 Linting Kickstarter with this PR took 6.84s vs 6.66s on master (2% slower)
📖 Linting Moya with this PR took 4.35s vs 4.37s on master (0% faster)
📖 Linting Nimble with this PR took 0.4s vs 0.38s on master (5% slower)
📖 Linting Quick with this PR took 0.18s vs 0.17s on master (5% slower)
📖 Linting Realm with this PR took 6.55s vs 6.48s on master (1% slower)
📖 Linting SourceKitten with this PR took 0.32s vs 0.31s on master (3% slower)
📖 Linting Sourcery with this PR took 1.91s vs 1.85s on master (3% slower)
📖 Linting Swift with this PR took 2.91s vs 2.85s on master (2% slower)
📖 Linting WordPress with this PR took 6.9s vs 6.77s on master (1% slower)

Generated by 🚫 Danger

@codecov-commenter
Copy link

codecov-commenter commented Mar 4, 2022

Codecov Report

Merging #3867 (439fbcc) into master (7f9f41a) will decrease coverage by 0.01%.
The diff coverage is 50.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3867      +/-   ##
==========================================
- Coverage   92.13%   92.11%   -0.02%     
==========================================
  Files         438      438              
  Lines       22542    22564      +22     
==========================================
+ Hits        20769    20785      +16     
- Misses       1773     1779       +6     
Impacted Files Coverage Δ
...tLintFramework/Rules/Idiomatic/ForceCastRule.swift 61.90% <50.00%> (-38.10%) ⬇️
Source/SwiftLintFramework/Models/Command.swift 92.30% <0.00%> (-1.29%) ⬇️
...iftLintFramework/Extensions/String+SwiftLint.swift 90.90% <0.00%> (+1.51%) ⬆️
...ource/SwiftLintFramework/Rules/Lint/MarkRule.swift 100.00% <0.00%> (+2.56%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7f9f41a...439fbcc. Read the comment docs.

jpsim added 11 commits March 7, 2022 12:15
Statically linking `lib_InternalSwiftSyntaxParser` to work around distribution
portability issues.
Benchmarks at a 6x speedup over SourceKit

| Framework | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| SourceKit | 517.8 ± 8.3 | 505.5 | 531.1 | 6.59 ± 0.43 |
| SwiftSyntax | 78.6 ± 5.0 | 72.6 | 92.1 | 1.00 |
@jpsim jpsim marked this pull request as ready for review March 7, 2022 17:20
@jpsim jpsim changed the title Add Swift Syntax proof of concept Integrate Swift Syntax in the force_cast rule Mar 7, 2022
@jpsim jpsim merged commit a43e52a into master Mar 7, 2022
@jpsim jpsim deleted the swift-syntax branch March 7, 2022 17:51
jpsim added a commit that referenced this pull request Mar 9, 2022
We've tried adding Swift Syntax support to SwiftLint in the past but had to turn it off in #3107 due to distribution and portability issues.

With https://github.com/keith/StaticInternalSwiftSyntaxParser it should be possible to avoid those issues by statically linking the internal Swift syntax parser so it's available no matter where users have Xcode installed on their computer.

By removing all calls to SourceKit (collecting comment commands + checking the current Swift version), there's a really significant performance improvement.

| Framework | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| SourceKit | 517.8 ± 8.3 | 505.5 | 531.1 | 6.59 ± 0.43 |
| SwiftSyntax | 78.6 ± 5.0 | 72.6 | 92.1 | 1.00 |

In practice, the SourceKit overhead will continue being there for as long as any rule being run is still looking up the SwiftLint syntax map though.
coffmark pushed a commit to coffmark/SwiftLint that referenced this pull request Apr 11, 2022
We've tried adding Swift Syntax support to SwiftLint in the past but had to turn it off in realm#3107 due to distribution and portability issues.

With https://github.com/keith/StaticInternalSwiftSyntaxParser it should be possible to avoid those issues by statically linking the internal Swift syntax parser so it's available no matter where users have Xcode installed on their computer.

By removing all calls to SourceKit (collecting comment commands + checking the current Swift version), there's a really significant performance improvement.

| Framework | Mean [ms] | Min [ms] | Max [ms] | Relative |
|:---|---:|---:|---:|---:|
| SourceKit | 517.8 ± 8.3 | 505.5 | 531.1 | 6.59 ± 0.43 |
| SwiftSyntax | 78.6 ± 5.0 | 72.6 | 92.1 | 1.00 |

In practice, the SourceKit overhead will continue being there for as long as any rule being run is still looking up the SwiftLint syntax map though.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants