Skip to content

Profile and analyze

Profile: find what is worth moving

When the goal is speed, measure before choosing anything:

sh
rust-anything profile <repo> -- node bench.mjs      # or: python3 bench.py, ruby bench.rb,
                                                    #     java -cp out Main, go test -run X -bench . ./pkg

profile runs a real workload under the language's profiler (node, cProfile, go test pprof, JFR, a Ruby tracer) and lists hot functions by inclusive time, their callers, and which loops to batch. Go profiles only through go test; C is not supported.

  • A small function called once per item is not worth porting alone: one call into Rust costs more than its work, and JITs (V8, the JVM, Go) run it in nanoseconds. Port it together with its callers, or batch it. The advice line says which, with the exact command.
  • Code that is already compiled (numba @njit, Cython, @jax.jit) runs as machine code: a Rust port gains little speed. profile lists it under "Already compiled".

Analyze: plan the port

sh
rust-anything analyze <repo> -o plan.md        # for people
rust-anything analyze <repo> --json            # for agents: schema rust-anything/analyze@1
rust-anything analyze <repo> --whole-app       # plus entry points, shape, dependencies, decisions

analyze lists units, the port order, risks with file:line, the bridge per unit, how well each dependency maps to a crate, and start_here: the best first ports. --whole-app adds the app's shape (CLI, server or library) and entry points, every dependency (imported or declared) with its crate, pieces (units that import each other move together) and numbered decisions with a recommended answer. See Port a whole app.

  • Packages (package.json) and source files; skips node_modules, build output, fixtures, playgrounds, tool configs. Vue/Svelte/Astro <script> blocks are parsed for imports.
  • Units: a folder of source files, or a file at a package's source root.
  • Waves: a unit's imports come in earlier waves; import cycles are ported together.
  • Bridge: napi-rs when the unit or anything it imports needs Node; wasm-bindgen for portable code; keep in JS for UI and editor code.
  • Readiness (how safe) and priority (safe and worth it: loops and string work, tests, size).
Risk Severity Example
String offsets high slice, indexOf, matchAll, the d flag: UTF-16 vs UTF-8
Regex syntax high lookaround, backreferences, y: not in the regex crate
Dynamic regex high new RegExp(userPattern): JS syntax at runtime
Dynamic code high eval, new Function, computed import()
Dynamic typing medium any, 'key' in value
Ordered collections medium Map, Set, Object.keys: insertion order
Async, generators medium promise and generator boundaries
Class inheritance, reflection medium extends, Proxy, Reflect, Symbol
Callback-shaped APIs medium function-typed params and methods: chatty bridges
Exceptions, numbers, JSON low throw, bitwise ops, JSON.stringify order

Crates for dependencies

analyze names the Rust crate for each library the code imports, with a fit of good, partial or none. A library missing from its table is reported as unknown; the table never guesses a crate. To add one, see Contributing.

Edit this page on GitHub →