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
scan: say Android runs on ART when a Gradle scan fails (#136)
EL4CTEO470600a78095
diff --git a/src/java.rs b/src/java.rsindex c118d3d..9d5cf30 100644--- a/src/java.rs+++ b/src/java.rs@@ -46,6 +46,33 @@ pub fn is_java(program: &str) -> bool {runner(program).is_some()}+/// A module of an Android app or library under `root`, relative to it: one with+/// src/main/AndroidManifest.xml, or whose build applies the Android Gradle plugin. Those run on+/// ART, which can't be profiled here (#136).+pub(crate) fn android_module(root: &Path) -> Option<PathBuf> {+ let mut stack = vec![root.to_path_buf()];+ while let Some(dir) = stack.pop() {+ let plugin = ["build.gradle.kts", "build.gradle"].iter().any(|f| {+ fs::read_to_string(dir.join(f))+ .is_ok_and(|t| t.contains("com.android.application") || t.contains("com.android.library"))+ });+ if plugin || dir.join("src").join("main").join("AndroidManifest.xml").is_file() {+ return Some(dir.strip_prefix(root).unwrap_or(&dir).to_path_buf());+ }+ let Ok(entries) = fs::read_dir(&dir) else { continue };+ for e in entries.flatten() {+ let name = e.file_name().to_string_lossy().into_owned();+ if e.path().is_dir()+ && !name.starts_with('.')+ && !["target", "build", "out", "node_modules", "src"].contains(&name.as_str())+ {+ stack.push(e.path());+ }+ }+ }+ None+}+/// The program as given, or its .cmd / .bat twin on Windows (mvn, gradlew).fn build_tool(program: &str, root: &Path) -> Result<String> {let base = if program.contains(['/', '\\']) { root.join(program) } else { PathBuf::from(program) };@@ -616,6 +643,25 @@ pub fn disable(ctx: &Ctx, port: &Port) -> Result<()> {mod tests {use super::*;+ #[test]+ fn finds_an_android_module() {+ let root = std::env::temp_dir().join(format!("fa-java-android-test-{}", std::process::id()));+ let _ = fs::remove_dir_all(&root);+ fs::create_dir_all(root.join("desktop/src/main/kotlin")).unwrap();+ fs::write(root.join("desktop/build.gradle.kts"), "plugins { kotlin(\"jvm\") }\n").unwrap();+ assert_eq!(android_module(&root), None);++ fs::create_dir_all(root.join("app/src/main")).unwrap();+ fs::write(root.join("app/src/main/AndroidManifest.xml"), "<manifest/>\n").unwrap();+ assert_eq!(android_module(&root), Some(PathBuf::from("app")));+ fs::remove_file(root.join("app/src/main/AndroidManifest.xml")).unwrap();+ assert_eq!(android_module(&root), None);++ fs::write(root.join("app/build.gradle"), "plugins { id 'com.android.application' }\n").unwrap();+ assert_eq!(android_module(&root), Some(PathBuf::from("app")));+ fs::remove_dir_all(&root).unwrap();+ }+#[test]fn the_recorder_adds_edge_cases() {use serde_json::json;diff --git a/src/pipeline.rs b/src/pipeline.rsindex 4b690ff..d1f3796 100644--- a/src/pipeline.rs+++ b/src/pipeline.rs@@ -39,13 +39,27 @@ pub fn scan(root: &Path, command: Vec<String>, duration: Option<f64>) -> Result<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], &command[1..], &ctx.root)?;+ // a failed scan of an Android project says why: its app runs on ART, not on a JVM (#136)+ let android = (crate::java::runner(&command[0]) == Some(crate::java::Runner::Gradle))+ .then(|| crate::java::android_module(&ctx.root))+ .flatten();+ let explain = |e: anyhow::Error| match &android {+ Some(module) => {+ let module =+ if module.as_os_str().is_empty() { "this project".into() } else { module.display().to_string() };+ e.context(format!(+ "{module} is an Android module, and Android apps run on ART, which fast-anything can't profile: it scans Java and Kotlin on a desktop JVM"+ ))+ }+ None => e,+ };+ let exe = lang.resolve(&command[0], &command[1..], &ctx.root).map_err(explain)?;ctx.state.command = command.clone();ui::step(format!("profiling {}", ui::bold(command.join(" "))));if let Some(d) = duration.filter(|_| lang != Lang::CSharp) {ui::line(format!(" stopping it after {d}s"));}- let profile = lang.profile(&ctx, &exe, &command[1..], duration)?;+ let profile = lang.profile(&ctx, &exe, &command[1..], duration).map_err(explain)?;let hotspots = hotspot::rank(profile.functions, profile.wall);ctx.state.lang = lang;ctx.state.runtime = Some(exe);