deoptkit

v0.3.0
deoptkit Checked 8 hours ago Published 21 days ago

A V8 deoptimization toolkit for AI agents and dev workflows: MCP server, findings engine, benchmark harness, and fix-verify comparison for inline caches…

These tools were reported by the server itself during our smoke test (tools/list), not copied from the README.

list_sessions Loaded sessions

List the V8 log sessions currently loaded in this server. Each session represents one parsed v8.log; use its id with the analysis tools.

load_log Load V8 log

Parse a V8 log file (v8.log, produced by `node --prof --log-deopt --log-ic --log-maps ...`) into a session for analysis. Returns the new session id, summary counts, and parser warnings.

ParameterTypeDescription
path *stringAbsolute path to the v8.log file to load
workspaceRootstringDirectory that reported paths are relative to (default: the server's working directory)

load_manifest Load bench manifest

Load every V8 log listed in a deoptkit manifest (written by the deoptkit/vitest bench preset to <outDir>/manifest.json) as sessions. Bench cases wrapped with benchObserved expose <name>_start/<name>_end markers for the fromMark/toMark window filters. The response's sessionIds can be passed straight to get_findings.

ParameterTypeDescription
path *stringPath to manifest.json, e.g. .deopt/manifest.json
workspaceRootstringDirectory that reported paths are relative to (default: the server's working directory)

profile_run Profile a command

Run a command under V8 optimization logging and load the result as a session — no flag knowledge needed. The executable must be a V8 host that accepts V8 flags (node, or a path to one); run npm-script workloads as `node path/to/script.js`. Then call get_findings; pass compareTo after a fix to get the before/after comparison in the same call.

ParameterTypeDescription
command *arrayExecutable and arguments, e.g. ["node", "bench/index.js", "--iterations", "100"]
categoriesarrayLog categories to record (default: all of ics, deopts, maps, profile, sources)
compareTostringA base session to compare the new session against; the response then includes `comparison`, the same payload compare_sessions returns
cwdstringWorking directory for the command
envobjectExtra environment variables (merged over the server's environment)
timeoutMsintegerKill the process after this long (default 60000)

get_findings Ranked findings

The primary analysis entry point: everything wrong in a session, ranked worst-first. Each finding has a severity (1-100), source location, and evidence; the explanation and suggested fix for each kind present are returned once under `kinds`. Start here, fix the top finding, re-profile, and compare. Pass sessionIds instead of sessionId to rank the findings of several sessions (every worker log of a vitest bench run) together; identical findings merge and list the sessions they appeared in.

ParameterTypeDescription
filestringOnly include items whose file path contains this substring
fromMarkstringWindow start: the first occurrence of this harness marker label (from deoptkit/harness mark/observed)
kindsarrayOnly include these finding kinds
limitintegerMaximum items to return (default 20)
offsetintegerItems to skip, for paging
sessionIdstringSession id returned by load_log (see list_sessions)
sessionIdsarraySeveral session ids (for example from load_manifest); findings are merged by identity across them
severityMinintegerOnly include findings at or above this severity
toMarkstringWindow end: the last occurrence of this harness marker label

list_ics Inline cache sites

List inline cache sites, worst state first. Filter by state (megamorphic/polymorphic/...), IC type, or file substring. Transitions are omitted unless includeTransitions is set, and then bounded by maxTransitions.

ParameterTypeDescription
sessionId *stringSession id returned by load_log (see list_sessions)
filestringOnly include items whose file path contains this substring
fromMarkstringWindow start: the first occurrence of this harness marker label (from deoptkit/harness mark/observed)
includeTransitionsbooleanInclude each site's recent state transitions (see maxTransitions)
limitintegerMaximum items to return (default 20)
maxTransitionsintegerWith includeTransitions: at most this many of the most recent transitions per site (default 20)
offsetintegerItems to skip, for paging
statesarrayOnly sites whose worst state is one of these
toMarkstringWindow end: the last occurrence of this harness marker label
typesarrayOnly these IC kinds

list_deopts Deopt sites

List deoptimization sites, most frequent first, with V8's bailout reasons. Eager deopts mean optimized code hit an unexpected type; repeated eager deopts at one site are a deopt loop.

ParameterTypeDescription
sessionId *stringSession id returned by load_log (see list_sessions)
filestringOnly include items whose file path contains this substring
fromMarkstringWindow start: the first occurrence of this harness marker label (from deoptkit/harness mark/observed)
kindsarrayOnly these deopt kinds
limitintegerMaximum items to return (default 20)
minCountintegerOnly sites with at least this many deopts
offsetintegerItems to skip, for paging
toMarkstringWindow end: the last occurrence of this harness marker label

list_functions CPU profile (flat)

List functions by CPU profile weight (a flat profile). selfTicks is time at the top of the stack; totalTicks counts any presence on the stack. Windows samples at ~15ms granularity.

ParameterTypeDescription
sessionId *stringSession id returned by load_log (see list_sessions)
filestringOnly include items whose file path contains this substring
fromMarkstringWindow start: the first occurrence of this harness marker label (from deoptkit/harness mark/observed)
limitintegerMaximum items to return (default 20)
offsetintegerItems to skip, for paging
sortBystringSort key (default selfTicks)
toMarkstringWindow end: the last occurrence of this harness marker label

get_profile CPU call tree

Call tree from the profiler samples: top-down (who calls what, from the roots) or bottom-up (hot functions and their callers). Defaults to the user's own code with builtins and dependencies folded into their nearest user caller, whose `folded` list names the folded functions that were actually running; pruned by maxDepth, limit (children per node), and minPercent (share of attributed ticks). Window with fromMark/toMark like get_findings.

ParameterTypeDescription
sessionId *stringSession id returned by load_log (see list_sessions)
fromMarkstringWindow start: the first occurrence of this harness marker label (from deoptkit/harness mark/observed)
justMyCodebooleanOnly show the user's own code; time in builtins and node_modules counts toward the nearest user caller (default true)
limitintegerMaximum children kept per node, heaviest first (default 10)
maxDepthintegerMaximum tree depth (default 8)
minPercentnumberDrop nodes below this percentage of the attributed ticks (default 1)
toMarkstringWindow end: the last occurrence of this harness marker label
viewstringtop-down roots the tree at outermost callers; bottom-up roots it at the functions that ran, with their callers beneath (default top-down)

get_map Hidden class details

Inspect one V8 object map (hidden class) by address: its parsed shape (properties in order, representation, flags), the transition chain that produced it, its sibling shapes from the same parent, and the IC sites that observed it. Map addresses appear in list_ics transitions (includeTransitions) and get_findings evidence (exampleMaps).

ParameterTypeDescription
address *stringMap address, e.g. 0x03a2c272a931
sessionId *stringSession id returned by load_log (see list_sessions)

get_function Function deep dive

Deep-dive one function: an annotated source snippet (from the sources embedded in the log) plus every IC site, deopt, and profile tick attributed to it. Identify the function by file substring plus functionName, or file plus a line number.

ParameterTypeDescription
file *stringSubstring of the script path/URL, e.g. src/hot.js
sessionId *stringSession id returned by load_log (see list_sessions)
contextLinesintegerLines of source to include (default 30)
functionNamestringFunction to anchor the snippet on
limitintegerMaximum items to return (default 20)
lineinteger1-based line to anchor on when functionName is not given

compare_sessions Compare before/after

Diff two sessions to verify a fix: findings resolved by the change, regressions it introduced, findings persisting (with severity movement), and per-function CPU deltas. Each finding kind's explanation and suggested fix are returned once under `kinds`. Profile before the change, apply it, profile again, then compare base vs head.

ParameterTypeDescription
baseSessionId *stringThe 'before' session
headSessionId *stringThe 'after' session