New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-14262] Foundation.Process has too much overhead for short-lived processes #3232
Comments
@swift-ci create |
Simplified example, without using Git. import Foundation
func runCommand() throws {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/true")
try task.run()
task.waitUntilExit()
}
try runCommand() $ hyperfine '../timing.swift'
Benchmark #​1: ../timing
Time (mean ± σ): 82.8 ms ± 4.3 ms [User: 9.9 ms, System: 7.2 ms]
Range (min … max): 68.1 ms … 89.6 ms 42 runs |
Added screenshot for Instruments results for the |
Testing similar Rust code (according to the stack trace, it is also calling // 0.66 seconds
use std::process::Command;
fn main() {
for _ in 0 .. 100 {
let _ = Command::new("/usr/bin/true").status();
}
} // 7.01 seconds
import Foundation
func runCommand() throws {
let task = Process()
task.executableURL = URL(fileURLWithPath: "/usr/bin/true")
try task.run()
task.waitUntilExit()
}
for i in 1 ..< 100 {
try runCommand()
} |
After talking to Karoy and David, this seems to be down to |
Attachment: Download
Environment
M1 Macbook Pro running macOS 11.2.1 (20D74)
Xcode 12.4 (12D4e), Swiftc (5.3.2 (swiftlang-1200.0.45 clang-1200.0.32.28))
Additional Detail from JIRA
md5: 54b4da616e867e4d69e4bdcf8ffd44e1
Issue Description:
I'm trying to use
Foundation.Process
for invoking git, and its own overhead is significantly more than the time to run the git command itself.Here is a simple git repo:
Here is how I measured the timing (using https://github.com/sharkdp/hyperfine)
Here is the Swift code.
Compiled that with
xcrun swiftc -O timing.swift -o ../timing
.I hope I'm not misusing the API or measuring the wrong thing...
The text was updated successfully, but these errors were encountered: