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) starts at 100 and subtracts, then clamps to 0–100:

    Term Weight
    Each risk its severity weight (high 6, medium 3, low 1) × ln(1 + count), so one high risk costs 4.2
    Size lines / 40
    Fan-in 1.5 per unit that imports it, at most 15
    Dependencies 12 per crate with no Rust fit, 4 per crate not in the table
    Tests +10 when a test file imports it directly; +4 when only its package has tests, counting a test in another package that imports this one by name
  • Density: loops and string-offset operations per 100 lines, rounded to one decimal before it is used.

  • Priority is half readiness, half value, rounded to a whole number and clamped to 0–100, where value adds up to 100. It uses the readiness fraction before that is rounded for the report, so two units that both print 100 can still score differently:

    Term Weight
    Compute density × 4, at most 50
    Tests 30 when a test file imports it directly, 15 when only its package has tests
    Size lines / 4 below 80, 20 from 80 up to (not including) 600, 10 at 600 and above
  • Start here takes ready units with at least 20 lines and at least one bridgeable export, ordered by priority, then readiness (both highest first), wave (earliest first), density (highest first) and id, and keeps the first ten. When fewer than three qualify it picks again from ready and caution units. When that is still empty (no unit of 20 lines has a bridgeable export) it drops the size floor. So one unit crossing 20 lines can change the list.

Every risk below appears in plans as title xN with the lines that raised it; this table says how bad it usually is and gives one example. The severities are the ones analyze scores with.

Risk Severity Where it bites
String offsets and slicing high TS/JS slice, indexOf, matchAll; string indexing and slicing in Python, Ruby, PHP (substr, strpos), Java, Kotlin, C#, Go; C strlen, strcpy, sprintf: offsets counted in UTF-16 units, characters or bytes, not Rust's UTF-8
Regex features the regex crate lacks high TS/JS, Python, Ruby, PHP, Java, Kotlin, C#, Go regexp, PowerShell -match/-replace: lookaround, backreferences, the y flag
Regexes built at runtime high TS/JS, Python, Ruby, PHP, Java, C#, PowerShell: new RegExp(pattern), re.compile(s), a pattern that is not a literal
Dynamic code (eval, new Function, computed import) high TS/JS eval, new Function, computed import(); Python exec, compile, __import__; Ruby eval, instance_exec; PHP eval, create_function; PowerShell Invoke-Expression, Add-Type
Dynamic typing medium TS/JS any, 'key' in value; Python getattr, isinstance; Ruby method; PHP ==; Java instanceof and casts; Kotlin is/as; C# dynamic, is/as; Go interface{} and type switches; PowerShell $script:/$global:
Insertion-ordered maps and object keys medium TS/JS Map, Set, Object.keys; PHP arrays; Ruby hashes; PowerShell [ordered] dictionaries
Async and promises medium TS/JS Promise and async/await; Python async/await; C# async/await
Generators medium TS/JS function*; Python, Ruby and PHP yield; C# yield and LINQ queries
Class inheritance medium TS/JS, Python, Ruby, PHP, Java, Kotlin, C#, PowerShell classes: extends, base classes, mixins and traits
Reflection and prototypes medium TS/JS Proxy, Reflect, Symbol; Python globals/vars; Ruby send, is_a?; PHP variable variables; Java java.lang.reflect, getClass(); Kotlin ::class; C# System.Reflection; Go reflect; C function-like macros
Callback-shaped APIs medium TS/JS, Ruby, PHP, Java, Kotlin, C#, Go, PowerShell script blocks: function-typed parameters make a chatty bridge
Exceptions low all ten: throw, raise, try, Go panic/recover/defer, C setjmp/longjmp/abort/exit/signal, PowerShell trap/Write-Error
Number semantics low TS/JS number, bitwise operators, parseInt; Python bitwise operators; PHP /; C# decimal
JSON round-trips low TS/JS JSON, Ruby, PHP, Go encoding/json, PowerShell ConvertTo-Json: key order, undefined, NaN
Integer width and overflow medium Python, Ruby and PHP ** and <<; Java, Kotlin, C# shifts, * and hash codes; Go and C shifts and conversions: wrap vs panic
Division and modulo medium Python, Ruby, PHP, Java, Kotlin, C#, Go, C: / and % on negatives, Python //
Hash iteration order high Python set; Java and Kotlin HashMap/HashSet; C# Dictionary/HashSet; Go map range; PowerShell @{} hashtables
Pointers and manual memory high C pointers, malloc, memcpy; Go unsafe and pointer types; C# unsafe
Concurrency medium Go goroutines and sync, Java and Kotlin threads and synchronized, C# lock and System.Threading, Python, Ruby, PHP and C threads, PowerShell Start-ThreadJob
Null references medium Java, C#, PHP null; Kotlin nullable types; Go and Ruby nil; C NULL; PowerShell $null
Runtime changes to code high Ruby define_method and friends, Python Class.method = ..., PHP class_alias/runkit_*/uopz_*
Already compiled (numba, Cython, JAX) medium Python: decorated code that is not plain Python any more
numpy array parameters high Python: np.ndarray arguments and returns
Platform-specific C (asm, volatile, bitfields, packing) high C: asm, volatile, :3 bitfields, #pragma pack
Clock and random numbers low TS/JS Date.now/Math.random, Python time.time/random/os.urandom, PowerShell Get-Date/Get-Random/New-Guid: record --pin-clock covers TS/JS with the napi bridge and Python; elsewhere compare by hand
Implicit output and the pipeline medium PowerShell: Write-Output, echo and values left uncaptured go to the pipeline
Case-insensitive comparison medium PowerShell -eq, -like, -match, -contains and switch ignore case
Implicit type conversion medium PowerShell: casts such as [int]"abc", and / on integers giving a double

These are the same 28 titles analyze can emit, with the severities it scores them at; src/risks.rs is the list.

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 →