October Update on the new Swift Parser

I'd like to highlight a few of the benefits we've seen by moving SwiftLint to use the new Swift Parser:

  1. Up to ~15% faster lint times on macOS (not measured on Linux)
  2. Significantly smaller binaries: portable_swiftlint.zip is 11.3 MB down from 20.9 MB
  3. No need to vendor the static lib_InternalSwiftSyntaxParser library and the various linker hacks needed to support that
  4. Prevent Linux distribution errors like SwiftSyntax comment parsing error since 0.47.0+ on Linux builds · Issue #4031 · realm/SwiftLint · GitHub
  5. Clearly the future of SwiftSyntax considering how aggressively Apple is trying to remove the C++ parser: See Recore deprecated SwiftSyntaxParser on top of SwiftParser. by DougGregor · Pull Request #767 · apple/swift-syntax · GitHub
  6. Possibly a lower barrier for new contributors given that it's 100% Swift

These are some really nice wins, so thanks to the SwiftSyntax folks for making it happen.

The main downside that we only discovered after moving over to the new parser is that memory usage has increased by a factor of 2x to 4x compared to the 5.7 SwiftSyntax release. Because we've been migrating more and more SwiftLint rules from using SourceKit to use SwiftSyntax, this has amplified the impact and now the latest SwiftLint release candidate (0.50.0-rc.3) takes about twice the amount of memory than the last stable release (0.49.1). If you're processing tens of thousands of files, this can easily mean GBs of increased memory usage.

I'm not comfortable cutting a new stable SwiftLint release until we can find a way to reduce the memory usage back to a reasonable level. Any help here would be greatly appreciated. I'm sharing this so others considering using new versions of Swift Syntax are aware.

28 Likes