mirror of https://github.com/sbt/sbt.git
The clean task is unreasonably slow because it does a lot of redundant io. In this commit, I update clean to be implemented using globs. This allows us to (optionally) route io through the file system cache. There is a significant performance improvement to this change. Currently, running clean on the sbt project takes O(6 seconds) on my machine. After this change, it takes O(1 second). To implement this, I added a new setting cleanKeepGlobs to replace cleanKeepFiles. I don't think that cleanKeepFiles returning Seq[File] is a big deal for performance because, by default, it just contains the history file so there isn't much benefit to accessing a single file through the cache. The reason I added the setting was more for consistency and to help push people towards globs in their own task implementations. Part of the performance improvement comes from inverting the problem. Before we would walk the file system tree from the base and recursively delete leafs and nodes in a depth first traversal. Now we collect all of the files that we are interested in deleting in advance. We then sort the results lexically by path name and then perform the deletions in that order. Because children will always comes first in this scheme, this will generally allow us to delete a directory. There is an edge case that if files are created in a subdirectory after we've created the list to delete, but before the subdirectory is deleted, then that subdirectory will not be deleted. In general, this will tend to impact target/streams because writes occur to target/streams during traversal. I don't think this really matters for most users. If the target directory is being concurrently modified with clean, then the user is doing something wrong. To ensure legacy compatibility, I re-implement cleanKeepFiles to return no files. Any plugin that was appending files to the cleanKeepFiles task with `+=` or `++=` will continue working as before because I explicitly add those files to the list to delete. I updated the actions/clean-keep scripted test to use both cleanKeepFiles and cleanKeepGlobs to ensure both tasks are correctly used. Bonus: add debug logging of all deleted files |
||
|---|---|---|
| .. | ||
| src | ||
| NOTICE | ||