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
node: verify unexported functions against the original
Mohit Mishra3f1205f8b500
diff --git a/src/node.rs b/src/node.rsindex 83515f2..2b1da84 100644--- a/src/node.rs+++ b/src/node.rs@@ -395,7 +395,16 @@ pub fn verify(ctx: &Ctx, port: &Port) -> Result<Verify> {"addon": ctx.lib_dir().join(format!("{}.node", port.ext)), "js_name": port.func, "func": port.func,"module_file": ctx.root.join(&port.file), "cases": dir.join("recordings.jsonl"), "out": out, "budget": 0.5,});- runner(ctx, node, "verify", job)?;+ // The original may not be exported: a block appended for this run hands it to the runner from+ // inside the module, then the file goes back byte for byte.+ let file = ctx.root.join(&port.file);+ let text = fs::read_to_string(&file).with_context(|| format!("reading {}", port.file))?;+ let hand_over = format!("if (globalThis.__fastAnythingOriginal) globalThis.__fastAnythingOriginal({});", port.func);+ let mut patches = crate::native::Patches::new(ctx)?;+ patches.write(&file, &backend::append_marked(&text, "//", &format!("verifying {}", port.id), &hand_over))?;+ let run = runner(ctx, node, "verify", job);+ patches.restore()?;+ run?;let mut v: Verify = serde_json::from_str(&fs::read_to_string(&out)?).context("reading verify results")?;v.built = true;Ok(v)diff --git a/src/node/runner.mjs b/src/node/runner.mjsindex 8206d1b..6527080 100644--- a/src/node/runner.mjs+++ b/src/node/runner.mjs@@ -504,9 +504,13 @@ async function verify(job) {const fast = createRequire(import.meta.url)(job.addon)[job.js_name];if (typeof fast !== "function") throw new Error(job.addon + " doesn't export " + job.js_name);let original = null;+ let handed = null; // from a block fast-anything appended to the module, so unexported functions work too+ globalThis.__fastAnythingOriginal = (fn) => {+ handed = fn;+ };try {const mod = await import(pathToFileURL(job.module_file).href);- original = mod[job.func] ?? mod.default?.[job.func] ?? null;+ original = handed ?? mod[job.func] ?? mod.default?.[job.func] ?? null;} catch {}const cases = readFileSync(job.cases, "utf8").split("\n").filter((l) => l.trim()).map((l) => JSON.parse(l));