Closed fredpi closed 4 years ago
I see it the same way as you do, but I'd give performance the higher priority here if the difference is considerable enough (meaning at least 15% faster). As I read your analysis, the more files there are, the bigger the performance gain is with rm -rf
, so I'd opt for keeping it that way for now. But I wonder where the performance gain comes from – maybe we can replicate the same behavior rm -rf
is doing under the hoods?
It could be that swift is performing some safety checks at runtime but we could have a look at the source of stdlib which will at least contain the linux version if it is bridged to NS libraries on macOS.
Source of the stdlib can be found here (POSIX implementation).
Internally, removeItem
calls internal func _removeItem(atPath path: String, isURL: Bool, alreadyConfirmed: Bool = false)
(with alreadyConfirmed = false
)
Closing this, as Accio is now deprecated.
An idea originating from #40 is to use
FileManager
for file operations instead of using commands like•
try! bash("mkdir '\(path)'")
•try! bash("rm -rf '\(path)'")
I benchmarked the
rm -rf
command againstFileManager.default.removeItem(atPath:)
and noticed that for folders only containing a few filesFileManager.default.removeItem(atPath:)
is roughly 2 times faster thanrm -rf
(0.06s vs 0.025s). However, when I copied a large iOS project into the folder whose deletion I benchmarked,rm -rf
performed better (average of 1.6s) vs.FileManager.default.removeItem(atPath:)
(average of 1.9s).Speed-wise,
rm -rf
is probably the better approach, yet style-wise I preferFileManager
.What are your thoughts on this?