SwiftFormat: Using globs in config file significantly slows down SwiftFormat
It’s the first time I’m trying to use the globs added in https://github.com/nicklockwood/SwiftFormat/issues/301.
After I add a simple *SwiftGen* glob, I notice that it significantly slows down swiftformat run time.
For the same number of files (116 in this example),
- Running
swiftformatwith globs in config: 11.69s - Running
swiftformatwithout any globs in config: 0.69s
There’s almost 20 times increase in execution time.
Not sure if processing globs should really slow down the execution. On the opposite, since with globs more files are ignored, it should run even faster.
Using swiftformat in git commit hooks or in Xcode build phase will add this extra delay.
I’ve noticed that the more globs there are in config, the longer it takes.
Looks like options parsing code in CommandLine.swift is slow when it comes to using expandGlobs. I’ve never used this API, so I’m not quite sure why is it slow and if it can be improved to be faster.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 22 (13 by maintainers)
@mgrebenets it works pretty much as you described. What’s not clear to me is why scanning the directory to expand the globs takes so much longer than scanning to format files.
I could probably improve performance by refactoring to do the glob matching and formatting in a single pass as you suggest, but even so I would expect that the current setup would only double the time taken at worst. The fact that it’s increasing it by orders of magnitude suggests there’s some sort of bug, and I’d like to identify what that is before refactoring anything.
@nicklockwood Here it is: https://github.com/mgrebenets/swiftformat-globs-demo It’s a completely hashed meaningless bunch of empty files. The extensions are well preserved as well as some keywords like “ios”, “Pods”, “Carthage”, “test”, “build”, “AutoGenerated”, etc., so it should be useful in benchmarking the globs implementation.