Don't rewrite it in Rust. Rewrite the 5% that's slow: profile your app, port the hot functions with your coding agent, prove they behave the same. Python, JS/TS, Ruby, Java, Kotlin, Go, PHP, C/C++, C#, R.
Rust agent-skillsai-agentsclaude-codeclaude-code-plugincodexdeveloper-toolsffimcpmcp-servernapi-rsnodejsoptimizationperformanceprofilerpyo3pythonrewrite-it-in-rustrubyrusttypescript
Resolve the temp folder in the duration tests; say why R can't use --duration on Windows
Mohit Mishra311163dc6832
diff --git a/src/backend.rs b/src/backend.rsindex 97dea8b..bc1e526 100644--- a/src/backend.rs+++ b/src/backend.rs@@ -142,7 +142,19 @@ impl Lang {/// Whether `scan --duration` can stop this language's apps.pub fn stops_after_duration(self) -> bool {// R: scan interrupts it with SIGINT, which Windows doesn't have- matches!(self, Lang::Python | Lang::Node | Lang::Go | Lang::Java | Lang::Kotlin | Lang::Ruby | Lang::Php | Lang::C | Lang::Cpp | Lang::CSharp) || (self == Lang::R && cfg!(unix))+ matches!(+ self,+ Lang::Python+ | Lang::Node+ | Lang::Go+ | Lang::Java+ | Lang::Kotlin+ | Lang::Ruby+ | Lang::Php+ | Lang::C+ | Lang::Cpp+ | Lang::CSharp+ ) || (self == Lang::R && cfg!(unix))}/// `duration` (see stops_after_duration): stop the app after that many seconds.diff --git a/src/cfamily.rs b/src/cfamily.rsindex a2f2de0..9b10341 100644--- a/src/cfamily.rs+++ b/src/cfamily.rs@@ -1453,7 +1453,10 @@ mod tests {eprintln!("no C compiler on PATH, skipping");return;};- let dir = std::env::temp_dir().join(format!("fa-c-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-c-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: work, foreverlet main = "long work(long n) {\n long s = 0;\n for (long i = 0; i < n; i++) s += i * i % 7;\n return s;\n}\n\nint main(void) {\n volatile long sink = 0;\n for (;;) sink += work(20000000);\n}\n";diff --git a/src/golang.rs b/src/golang.rsindex 29dc720..13ac5d6 100644--- a/src/golang.rs+++ b/src/golang.rs@@ -749,7 +749,10 @@ func main() {eprintln!("no go on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-go-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-go-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();fs::write(dir.join("go.mod"), "module demo\n\ngo 1.22\n").unwrap();// a server's shape: work, foreverdiff --git a/src/java.rs b/src/java.rsindex 162a385..0ac512f 100644--- a/src/java.rs+++ b/src/java.rs@@ -618,7 +618,10 @@ mod tests {eprintln!("no java on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-java-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-java-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: work, foreverlet app = "public class App {\n static long work(int n) {\n long s = 0;\n for (int i = 0; i < n; i++) s += (long) i * i % 7;\n return s;\n }\n\n public static void main(String[] args) throws Exception {\n long sink = 0;\n while (true) {\n sink += work(20_000_000);\n Thread.sleep(1);\n }\n }\n}\n";diff --git a/src/node.rs b/src/node.rsindex 69c81da..5a8eab3 100644--- a/src/node.rs+++ b/src/node.rs@@ -1042,7 +1042,10 @@ for (const worst of [eprintln!("no node on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-node-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-node-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: work on a timer, foreverlet app = "function work(n) {\n let s = 0;\n for (let i = 0; i < n; i++) s += i * i;\n return s;\n}\nsetInterval(() => work(3e6), 5);\n";diff --git a/src/php.rs b/src/php.rsindex daee577..13a4500 100644--- a/src/php.rs+++ b/src/php.rs@@ -442,7 +442,10 @@ mod tests {eprintln!("no php with pcntl on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-php-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-php-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: some work, then a long blocking waitlet app = "<?php\nfunction work(int $n): int\n{\n $s = 0;\n for ($i = 0; $i < $n; $i++) $s += $i * $i % 7;\n return $s;\n}\n\nfor ($k = 0; $k < 3; $k++) work(300000);\nsleep(3600);\n";diff --git a/src/pipeline.rs b/src/pipeline.rsindex fe74d2e..e630026 100644--- a/src/pipeline.rs+++ b/src/pipeline.rs@@ -36,7 +36,7 @@ pub fn scan(root: &Path, command: Vec<String>, duration: Option<f64>) -> Result<let lang = crate::cfamily::refine(Lang::detect(&command[0])?, &command[1..]);let lang = crate::kotlin::refine(lang, &command[0], &ctx.root);if let Some(d) = duration {- ensure!(lang.stops_after_duration(), "--duration works for Python, JavaScript/TypeScript, Go, Java, Kotlin, Ruby, PHP, C, C++, R and C# apps only so far");+ ensure!(lang.stops_after_duration(), "--duration stops R apps with SIGINT, which Windows doesn't have");ensure!(d.is_finite() && d > 0.0, "--duration takes a number of seconds, e.g. --duration 30");}let exe = lang.resolve(&command[0], &ctx.root)?;diff --git a/src/r.rs b/src/r.rsindex 49556c2..e481d5f 100644--- a/src/r.rs+++ b/src/r.rs@@ -640,7 +640,10 @@ mod tests {eprintln!("no Rscript on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-r-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-r-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: some work, then a long blocking waitlet app = "work <- function(n) {\n s <- 0\n for (i in seq_len(n)) s <- s + i * i %% 7\n s\n}\n\nif (sys.nframe() == 0) {\n for (k in 1:3) work(400000)\n Sys.sleep(3600)\n}\n";diff --git a/src/ruby.rs b/src/ruby.rsindex dc4c929..4d4686b 100644--- a/src/ruby.rs+++ b/src/ruby.rs@@ -354,7 +354,10 @@ mod tests {eprintln!("no ruby on PATH, skipping");return;}- let dir = std::env::temp_dir().join(format!("fa-ruby-duration-test-{}", std::process::id()));+ let tmp = std::env::temp_dir();+ // macOS's temp folder is behind a symlink; the profile has the real paths+ let tmp = if cfg!(windows) { tmp } else { tmp.canonicalize().unwrap() };+ let dir = tmp.join(format!("fa-ruby-duration-test-{}", std::process::id()));fs::create_dir_all(&dir).unwrap();// a server's shape: some work, then a long blocking waitlet app = "def work(n)\n (0...n).sum { |i| i * i % 7 }\nend\n\nif __FILE__ == $0\n 3.times { work(200_000) }\n sleep 3600\nend\n";