JamitLabs / Accio

A dependency manager driven by SwiftPM that works for iOS/tvOS/watchOS/macOS projects.
MIT License
664 stars 32 forks source link

Use FileManager for file operations #41

Closed fredpi closed 4 years ago

fredpi commented 5 years ago

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 against FileManager.default.removeItem(atPath:) and noticed that for folders only containing a few files FileManager.default.removeItem(atPath:) is roughly 2 times faster than rm -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 prefer FileManager.

What are your thoughts on this?

Jeehut commented 5 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?

mrylmz commented 5 years ago

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.

fredpi commented 5 years ago

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)

fredpi commented 4 years ago

Closing this, as Accio is now deprecated.