Skip to content

perf(ghidra): decompile upcoming export functions in parallel - #14847

Merged
morluto merged 19 commits into
mainfrom
perf/ghidra-parallel-decompile
Nov 27, 2026
Merged

morluto merged 19 commits into
mainfrom
perf/ghidra-parallel-decompile

Conversation

@morluto

@morluto morluto commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

Addresses #14836. decompile-all on Ghidra decompiles each window of upcoming functions with several native decompiler processes. Stacked on #14843, whose decompile result cache it fills; review that PR first.

Problem and expected behavior

The bridge holds one DecompInterface, and the export requests one function at a time. Ghidra ships ParallelDecompiler; a standalone script over one target's 3,544 functions measured 32.6 s serial and 12.3 s parallel on 10 cores.

Change and scope

The export passes an advisory upcomingDecompiles execution option on the first procedure_pseudo_code request of each window of up to 32 functions it will actually request (verified files, recorded externals and the caller's limit are excluded). The Ghidra provider forwards it as a decompile_read_ahead request field. Before answering that procedure_pseudo_code request, after its session checks, the bridge decompiles the window with a pooled DecompilerCallback on a Ghidra ConcurrentQ and stores completed results in the decompile cache. Each function's own request then answers from the cache, so per-function results, failures, deadlines, the journal and file order are produced by the same code as before.

Deadline: the request that carries the window (its own function is first) waits for the window only within its own decompile deadline. It consumes the window's outcome for its function whatever it is, including a failure or timeout, and does not decompile it again, so one configured deadline never elapses twice. Once it has that result and the deadline has passed, siblings still running are cancelled through their task monitors and stay uncached; their own requests decompile them and report any failure as a serial export does. With an unbounded deadline the window runs to completion, as the caller accepted.

The hint is advisory: selectors past one window (32, the number of retained results) are ignored rather than refusing the request.

Pool: the decompilers run on a private GThreadPool, not Ghidra's shared "Parallel Decompiler" pool, which ParallelDecompiler would resize. They are released after 30 seconds without a window (an internal constant: read-ahead serves consecutive requests of one workflow), on Program edits, payload-limit changes and shutdown, because pooled decompilers hold native state for the Program and options they opened with. Workers are capped at eight and by the host's processor count; the cap and the window size are fixed ceilings with their reasons stated in the source.

Not included: batch_decompile, other providers (the option is advisory and ignored elsewhere), and a streaming design that would let one very large function overlap with later windows.

Contribution scope: not applicable; a fix within existing boundaries.

Contract and boundary impact

  • Semantic owner and earliest changed stage: The export owns which functions it will request; the bridge owns the decompiler and its cache. The port carries one advisory fact between them.
  • Contribution scope fit and linked maintainer decision: ordinary fix within existing boundaries; not applicable
  • CLI and MCP/tool-catalog contract: No tool schema or result change. One new optional bridge request field.
  • Provider, bridge, target-format, or platform compatibility: Ghidra only. Uses ghidra.app.decompiler.parallel.DecompilerCallback, generic.concurrent.ConcurrentQ and a private GThreadPool, present in Ghidra 12.2; older supported releases were not checked.
  • Evidence, artifact, provenance, or reconstruction contract: Unchanged. Every exported body was compared with a serial export.
  • Target selection, authority, upstream behavior, and cleanup details (if applicable): none
  • Generated metadata, package, or installation impact: none

Expected effects:

  • Read existing files or captured data.
  • Launch or attach to a process.
  • Inject instrumentation or run scripts/code.
  • Change process memory, registers, files, or configuration.
  • Contact network services.
  • Recover protected code or work around protections.
  • Documentation or usability only; no target interaction.
  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: decompileAll.test.ts: a limit of one names nothing; a resume names the remaining functions once, in request order, and skips the verified file; 40 functions form two consecutive windows, a limit of 34 ends the second window, and a window whose first function is external is carried by the next request. GhidraClientWire.test.ts: the request field is written. Real Ghidra, scripts/verify-real-ghidra-decompiler-failure.mjs: the probe injects a window whose carrying function times out beside a sibling that never finishes, and checks that the request reports decompile_timed_out without decompiling again, returns within its 1 s deadline plus slack, leaves the cancelled sibling uncached and uses REA's own pool; a 40-selector hint parses to its first 32. With foreground reuse disabled the probe fails. The probe had stopped running against the current bridge (a removed Request constructor, old failure wording, and injected decompilers that result reuse never called); those are repaired here.

  • Base reproduction or other evidence: Executed, real Ghidra, checkpoint restored, 10 cores:

    Target Functions written Decompile requests, serial With read-ahead Whole command
    769 KB Mach-O 1,441 12.8 s 10.8 s 32.4 s to 30.7 s
    1.5 MB Mach-O 3,544 34.2 s 27.2 s not comparable; the serial run included first-time analysis

    All 1,441 and all 3,544 function bodies were identical to the serial exports. After the deadline and pool changes, a full decompile-all of the 769 KB Mach-O (1,441 functions, fresh analysis) took 50.7 s wall, and all 1,441 bodies matched three earlier exports. In an MCP session, nine decompiler processes after decompile_all dropped to one, the session's own, after 35 s idle. analyze_function dossiers for four functions had identical digests whether the decompile came from the pool or the session decompiler. After a rename, a caller's next decompile showed the new name.

  • User-visible CLI/MCP output (if applicable): unchanged

  • Remaining proof gaps: The deadline bound was verified with injected decompilers; no natural function was found that times out inside a window. The measured gain is 1.2x to 1.3x on decompile time, well short of the 2.7x of a single parallel pass, because a window waits for its largest function: on the larger target 8 of 101 windows account for 14.7 s of 25.5 s. The remaining export time is per-function fsyncs ([Feature] decompile-all: per-function fsyncs cost as much as decompiling #14830). Memory use of eight decompiler processes on large targets was not measured. An earlier version that built a pool per window was 3.5x slower than serial; nothing in the tests would catch that regression.

Validation performed

  • npm run test:local -- src/application/decompileDirectory/decompileAll.test.ts src/ghidra/GhidraClientWire.test.ts — 79 tests passed
  • npm run build:cached — passed
  • node scripts/verify-ghidra-bridge-sources.mjs against Ghidra 12.2 — bridge compiles
  • node scripts/verify-real-ghidra-decompiler-failure.mjs against Ghidra 12.2 — passed, including the six read-ahead checks
  • npm run test:focused -- tests/boundary/mcp/ghidraDecompileDeadlineLifetime.test.ts tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts tests/boundary/cli/analysisViewCli.test.ts — 41 tests passed
  • Manual rea decompile-all and MCP sessions against Ghidra 12.2 — results above
  • npm run check:fast — typecheck, lint and architecture guards passed
  • npx oxfmt --check on the changed files — passed

Compatibility, safety, and release

  • Breaking changes or migration steps: none
  • Real Hopper/Ghidra, browser, or OS coverage: Ghidra 12.2 on macOS arm64, Node 24.22.1, Ghidra 12.2, JDK 25, by hand.
  • Package or release metadata impact: none
  • Security, privacy, process, or containment review: Launches up to eight additional native decompiler processes owned by the Ghidra JVM for the session; they are disposed after 30 s idle and on edits, option changes and shutdown, and none remained after the sessions closed.

Author readiness

Human owner: @morluto

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Review follow-up

  • Includes the fix(ghidra): reuse completed decompiles and decompile code outside functions #14843 payload fix. Reads between exported functions no longer discard read-ahead results or dispose the pool when ghidra.decompile_max_payload_mib is set.
  • The read-ahead window is planned from the same per-function decision the export loop makes, so a resume with deleted files or file conflicts prepares only functions it will request within its limit.
  • The real-Ghidra probe scripts/verify-real-ghidra-decompiler-failure.mjs covers both bridge fixes and passes on Ghidra 12.2.

@morluto
morluto marked this pull request as ready for review November 27, 2026 03:19
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T10:14:40.544573Z 781b53b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 918e7ea902

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issue was established.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was established.

Summary

Adds parallel read-ahead for Ghidra decompile-all, while keeping individual function requests and export order.

  • The export sends Ghidra windows of functions it will decompile next.
  • Ghidra decompiles upcoming export functions in parallel.

Diagram

sequenceDiagram
  participant Export
  participant Provider
  participant Bridge
  participant Workers
  participant Cache
  Export->>Provider: Function request with upcoming selectors
  Provider->>Bridge: Authenticated request with advisory hint
  Bridge->>Workers: Decompile window
  Workers-->>Bridge: Completed results
  Bridge->>Cache: Retain completed results
  Bridge-->>Export: Carrying function result or failure
  Export->>Bridge: Later function requests
  Bridge->>Cache: Look up each result
  Bridge-->>Export: Individual results in request order
Loading

Reviews (7) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
A file-offset selector that mapped to disassembled code without a function
failed with advice to choose an inventory procedure, which cannot name that
code. The failure now states the fact and that procedure_pseudo_code can
decompile it by the mapped analysis address.

One predicate now decides that an address holds code outside every function
for the address, file-offset and procedure_not_found paths, and the bridge
imports UndefinedFunction and SoftReference like its other dependencies.
The bridge ran the read-ahead window in the generic serve loop, before the
ping, analysis-incomplete and read-only checks and for any method that
carried the field. It now runs only for procedure_pseudo_code, after those
checks. The pool state sits with the other decompiler fields and its Ghidra
types are imported.

The export tests now cover consecutive windows, a limit that ends inside a
window and a window whose first function sends no decompile request. The
provider guide states that a function failing or timing out inside a window
is attempted again by its own request, and how long the pool lives.
@morluto

morluto commented Nov 27, 2026

Copy link
Copy Markdown
Owner Author

Review summary

Reviewed the diff and surrounding code against Ghidra 12.2 sources and real runs (macOS arm64, 10 cores, JDK 25). The updated #14843 branch is merged in (93d83e1, no rebase), followed by one commit: 37b65f8.

Changed

  • Read-ahead ran in the generic serve loop. decompileAhead was called before the ping, analysis_incomplete and read-only checks and for any method carrying the field. It now runs only in the procedure_pseudo_code case, after those checks. Found by reading; the TypeScript client never sends the field elsewhere, so this was not reachable from REA and is a placement fix, not a reproduced failure. After the move, a 20-function window still filled the cache (analyze_function on entry 0.4 s against 3.9 s fresh).
  • Window tests. The existing test used three functions, so it never crossed a window boundary. Added one test: 40 functions form windows of 32 and 8; a limit of 34 ends the second window at 2; a window whose first function is external is carried by the next request. It passed against the existing window code, so it closes a coverage gap and found no defect.
  • Cleanup. Pool field and worker constant moved beside the other decompiler state; DecompilerCallback, ParallelDecompiler and GThreadPool imported.
  • Docs. The guide now says a function that fails or times out inside a window is attempted again, and how long the pool lives.

Confirmed, not changed: needs a maintainer decision

  • A configured decompile deadline elapses twice for a function that reaches it. With ghidra.decompile_timeout_seconds = 1 on ssh_x64, decompile_all from entry took 1.1 s with limit: 1 (no window) and 2.6 s with limit: 3 (window, then the function's own request). The same holds for any function that fails in a window. Remembering window failures would remove the second wait, but a function that only timed out under eight-way contention would then be reported as timed out where a serial export succeeds, which breaks the "same as a serial export" claim. I left the behavior and documented it. The default has no deadline, so this affects only sessions that set one.

Checked, no defect found

  • Result sharing. Complete dossiers for three functions and the summary for entry were identical fresh, from the session decompiler's cache and from pooled results. The cache is cleared at every point the pool is disposed except shutdown, so no pooled result outlives its interface in use.
  • Threading. The pool callback only returns the results; the cache map is written on the bridge thread after decompileFunctions returns. ConcurrentQ removes its cancel listener on dispose.
  • Disposal and cancellation. SIGINT during a window on ssh_x64: 9 decompile processes and the JVM before, CLI exit 130 with cleanup: complete, none surviving. The pool is released in run()'s finally, on edits and on payload-limit changes. Nothing in the bridge cancels the monitor in-band, so cancellation is session closure.
  • Timeouts. The pool calls the same decompileFunction(f, timeout, monitor); 0 means no timer in both paths.
  • Parser and wire. Non-array, non-string or more than 32 entries reject the request and close the connection, as other malformed fields do. The field counts toward the request-size admission. An older bridge rejects the unknown key; bridge sources ship with the client, so the versions cannot differ in practice.
  • Limits. rea-numeric-limits and fixed-ceilings pass. The window size and worker cap are batching sizes with reasons in the source; neither refuses work.

Left open, with reasons

  • GThreadPool.getSharedThreadPool("Parallel Decompiler").setMaxThreadCount(...) changes a JVM-wide pool (default: Ghidra's default pool size). No analyzer runs in the bridge JVM after serving starts, so nothing else observes it today. A private pool needs ConcurrentQBuilder directly instead of ParallelDecompiler.
  • The window size is 32 in decompileAll.ts and in the bridge's parser bound. GhidraProviderClient forwards the hint unclamped, so a port caller naming more than 32 would have the request rejected and the connection closed, which is not advisory. No caller does this today. A clamp in the provider, or a bridge that truncates, would make it safe.
  • Up to eight idle decompiler processes stay for the rest of an MCP session after one export, until an edit or close. Their memory was not measured.
  • The LRU evicts a window's earliest results when the next window fills (after a 34-function export, analyze_function on the first function ran the decompiler again). Expected for 32 entries; only a repeat cost.
  • If the first request of a window is answered without reaching the bridge, the hint is dropped and that window runs serially. Not reproduced.
  • I did not repeat the full serial-versus-parallel body comparison or the timing table.

Commands

  • npm run test:local -- src/application/decompileDirectory/decompileAll.test.ts src/ghidra/GhidraClientWire.test.ts: 2 files, 79 tests passed.
  • npm run test:focused -- tests/boundary/filesystem/ghidraBridgeSources.test.ts tests/boundary/providers/ghidra/ghidraBridgeHelpers.test.ts tests/boundary/providers/ghidra/ghidraClient.test.ts: 3 files, 134 tests passed.
  • npm run check:fast: passed. npm run docs:check: passed.
  • node scripts/verify/rea-numeric-limits.mjs, node scripts/verify/fixed-ceilings.mjs: passed.
  • GHIDRA_INSTALL_DIR=... node scripts/verify-ghidra-bridge-sources.mjs: bridge sources compile against Ghidra 12.2.
  • npx oxfmt --check on the changed files: passed.
  • Real MCP and CLI runs against Ghidra 12.2 on ssh_x64: results above.
  • Not run: npm run verify:ghidra, npm run check:pr.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37b65f82b9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread bridge/ghidra/ReaGhidraBridge.java Resolved
A file offset names the same location as its mapped analysis address, but
an offset that mapped to code Ghidra disassembled without a function was
refused while the address decompiled. The offset now resolves through the
same on-the-fly UndefinedFunction path and limitation, and its selection
reports the inferred entry as procedure_address. The refusal that sent the
caller back to the address form is removed.
…e-orphan-code' into perf/ghidra-parallel-decompile
…dline

A request that carried a read-ahead window waited for every function in it,
then decompiled its own function again when the window's attempt failed or
timed out, so one configured deadline could elapse twice. That request now
waits only within its own deadline, consumes the window's outcome for its
function whatever it is, and cancels siblings still running once it has its
result and the deadline has passed; they stay uncached for their own requests.

The hint is advisory, so selectors past one window are now ignored instead
of refusing the request. Pooled decompilers run on a private thread pool
rather than resizing Ghidra's shared "Parallel Decompiler" pool, and are
released after 30 seconds without a window.
The decompiler failure probe now injects a read-ahead window whose carrying
function times out beside a sibling that never finishes. It checks that the
request reports the timeout without decompiling again, waits only within its
deadline, leaves the cancelled sibling uncached, uses REA's own thread pool,
and that a longer hint is clamped to one window.

The probe no longer ran against the current bridge: it used a removed
three-argument Request constructor, expected the old timeout and failure
wording, and injected decompilers that completed-result reuse never called.
It now builds full requests, matches the current messages by prefix and
clears reused results before each injection.
…ptions

A request that omits decompile_max_payload_mib now leaves the session's
payload limit unchanged instead of resetting it to the Ghidra default,
so an instruction or metadata read no longer discards completed
decompiles. An explicit null still selects the installed default.

Boundary limitations for a reused decompile of code outside every
function now use the function the decompile widened, not a fresh
entry-only UndefinedFunction.
…e-orphan-code' into perf/ghidra-parallel-decompile

# Conflicts:
#	bridge/ghidra/ReaGhidraBridge.java
…e-orphan-code' into perf/ghidra-parallel-decompile
… makes

The read-ahead window decided which functions would be requested from
journal history alone. A journaled write whose file was later deleted
is requested again, and file problems spend the caller's limit, so a
resume could prepare functions outside its limit while the ones it
requested got no preparation.

Each function is now decided once by the same check the loop uses. The
window keeps those decisions for the loop, counts every attempt against
the limit, and names only functions that will be decompiled.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fac44cef0f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

…ends it

A function the window named first could send no decompile request, for
example when procedure_info classifies it as external, so the next
request sent a hint headed by that function. A provider reads the head
as the carrying request's own function, so the bridge could not keep
that request's window result and might decompile it again.

The request now takes the planned window from its own function on.
…decompile

# Conflicts:
#	bridge/ghidra/ReaGhidraBridge.java
#	docs/providers/ghidra-provider.md
#	src/application/decompileDirectory/decompileAll.ts
@morluto
morluto enabled auto-merge (squash) November 27, 2026 09:52
…decompile

# Conflicts:
#	src/application/decompileDirectory/decompileAll.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant