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

Use faster dictionaries traversing for AST Rules #2951

Closed
wants to merge 6 commits into from

Conversation

PaulTaykalo
Copy link
Collaborator

No description provided.

@PaulTaykalo PaulTaykalo force-pushed the speedup/faster-dictionary-traversing branch from 2a7fb4d to 1b45501 Compare November 8, 2019 22:22
Source/SwiftLintFramework/Protocols/ASTRule.swift Outdated Show resolved Hide resolved
@SwiftLintBot
Copy link

SwiftLintBot commented Nov 8, 2019

1 Warning
⚠️ This PR may need tests.
12 Messages
📖 Linting Aerial with this PR took 1.28s vs 1.4s on master (8% faster)
📖 Linting Alamofire with this PR took 2.25s vs 2.72s on master (17% faster)
📖 Linting Firefox with this PR took 6.73s vs 8.15s on master (17% faster)
📖 Linting Kickstarter with this PR took 13.57s vs 16.39s on master (17% faster)
📖 Linting Moya with this PR took 1.2s vs 1.53s on master (21% faster)
📖 Linting Nimble with this PR took 1.33s vs 1.51s on master (11% faster)
📖 Linting Quick with this PR took 0.53s vs 0.55s on master (3% faster)
📖 Linting Realm with this PR took 2.16s vs 2.5s on master (13% faster)
📖 Linting SourceKitten with this PR took 0.89s vs 1.0s on master (10% faster)
📖 Linting Sourcery with this PR took 2.28s vs 3.16s on master (27% faster)
📖 Linting Swift with this PR took 11.44s vs 13.04s on master (12% faster)
📖 Linting WordPress with this PR took 14.88s vs 17.78s on master (16% faster)

Generated by 🚫 Danger

@PaulTaykalo PaulTaykalo force-pushed the speedup/faster-dictionary-traversing branch from 1b45501 to f817351 Compare November 8, 2019 22:54
@jpsim
Copy link
Collaborator

jpsim commented Nov 8, 2019

5-15% faster across the board 👏

@PaulTaykalo
Copy link
Collaborator Author

PaulTaykalo commented Nov 8, 2019

@jpsim just a sec there's a another place with the same logic

@PaulTaykalo
Copy link
Collaborator Author

Oh.. there are multiple places with this kind of structure traverse

@PaulTaykalo
Copy link
Collaborator Author

I'm thinking about some generic traverser

@PaulTaykalo
Copy link
Collaborator Author

PaulTaykalo commented Nov 9, 2019

@jpsim Okay, I'm done for now.
If you have thoughts on how this traversing can be named differently - I'm all ears

  • Docs on traversing functions needed
  • Private?/public traversing functions
  • Conditional traversing needed to be handled (maybe this is out of this PR)
  • use subDict.expressionKind.map { violations(in: file} syntax over guard ?

I will not be able to fix this in few next days. So feel free to update it, or just leave comments and I'll fix those.

@PaulTaykalo PaulTaykalo force-pushed the speedup/faster-dictionary-traversing branch from 1a976c7 to 8aafd73 Compare November 9, 2019 21:27
Copy link
Collaborator

@jpsim jpsim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! I tried seeing what it would look like to use map instead of guard as well, but prefer the guard at the end.

@@ -46,6 +46,10 @@
[PaulTaykalo](https://github.com/PaulTaykalo)
[#2949](https://github.com/realm/SwiftLint/issues/2949)

* Faster dictionaries traversing for AST Rules.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

Speed up recursively executed rules (all AST rules and some others) by avoiding the creation of many intermediate collections when accumulating results.

@@ -151,6 +151,50 @@ public struct SourceKittenDictionary {
}
}

extension SourceKittenDictionary {
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: use markdown-style code markup using backticks instead of | so it renders nicely in Xcode.

Suggested change
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node.
/// Traversing all substructures of the dictionary hierarchically, calling `traverseBlock` on each node.

@@ -151,6 +151,50 @@ public struct SourceKittenDictionary {
}
}

extension SourceKittenDictionary {
/// Traversing all substuctures of the dictionary hierarchically, calling |traverseBlock| on each node.
/// Traversing using depth first strategy, so deepest substructures will be passed to |traversBlock| first
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: traversBlock -> traverseBlock

return result
}

private func traverseDepthFirst<T>(collectingValuesInto array:inout [T],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space between : and inout:

Suggested change
private func traverseDepthFirst<T>(collectingValuesInto array:inout [T],
private func traverseDepthFirst<T>(collectingValuesInto array: inout [T],

}

private func traverseWithParentDepthFirst<T>(
collectingValuesInto array:inout [T],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: space between : and inout:

Suggested change
collectingValuesInto array:inout [T],
collectingValuesInto array: inout [T],

@jpsim
Copy link
Collaborator

jpsim commented Nov 9, 2019

Pushed this with minor edits to master because I'm cutting a release now 😄

@jpsim jpsim closed this Nov 9, 2019
@PaulTaykalo PaulTaykalo deleted the speedup/faster-dictionary-traversing branch November 10, 2019 06:14
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