ashfurrow / danger-ruby-swiftlint

A Danger plugin for SwiftLint.
https://rubygems.org/gems/danger-swiftlint
MIT License
203 stars 81 forks source link

Optimize performance of include/exclude test #141

Closed AliSoftware closed 4 years ago

AliSoftware commented 4 years ago

Why?

On large codebases, the high number of calls to Find.find (which builds a recursive list of all files in directory and subdirectories) for every single file to lint (Find.find called on each iteration of the reject {…} and select {…} loops) ends up iterating on the whole file hierarchy multiple times, and affects performance.

How?

Just stored the result of Find.find(*excluded_path) and Find.find(*included_path) in a local array so that it iterates only once, then used that pre-computed local array inside each iteration of reject/select

Result

We just had a CircleCI timeout because of that performance issue, which made swiftlint.lint_files exceed the 10 minutes job timeout. On contrast, once pointing to this patch, the lint only took a few seconds.

ashfurrow commented 4 years ago

I have released this to RubyGems as version 0.24.1. Thanks again!

AliSoftware commented 4 years ago

That was fast! Thx 👍