Repository navigation
perf(ghidra): decompile upcoming export functions in parallel - #14847
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
[Medium impact] The PR appears safe to merge; no new actionable issue was established. SummaryAdds parallel read-ahead for Ghidra
DiagramsequenceDiagram
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
Reviews (7) · Last reviewed commit: "Merge remote-tracking branch 'origin/mai..." · Reviewed by Greptile |
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.
…f/ghidra-parallel-decompile
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.
Review summaryReviewed 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
Confirmed, not changed: needs a maintainer decision
Checked, no defect found
Left open, with reasons
Commands
|
There was a problem hiding this comment.
💡 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".
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.
There was a problem hiding this comment.
💡 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
…decompile # Conflicts: # src/application/decompileDirectory/decompileAll.ts
Summary
Addresses #14836.
decompile-allon 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 shipsParallelDecompiler; 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
upcomingDecompilesexecution option on the firstprocedure_pseudo_coderequest 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 adecompile_read_aheadrequest field. Before answering thatprocedure_pseudo_coderequest, after its session checks, the bridge decompiles the window with a pooledDecompilerCallbackon a GhidraConcurrentQand 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, whichParallelDecompilerwould 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
ghidra.app.decompiler.parallel.DecompilerCallback,generic.concurrent.ConcurrentQand a privateGThreadPool, present in Ghidra 12.2; older supported releases were not checked.Expected effects:
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 reportsdecompile_timed_outwithout 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 removedRequestconstructor, 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:
All 1,441 and all 3,544 function bodies were identical to the serial exports. After the deadline and pool changes, a full
decompile-allof 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 afterdecompile_alldropped to one, the session's own, after 35 s idle.analyze_functiondossiers 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 passednpm run build:cached— passednode scripts/verify-ghidra-bridge-sources.mjsagainst Ghidra 12.2 — bridge compilesnode scripts/verify-real-ghidra-decompiler-failure.mjsagainst Ghidra 12.2 — passed, including the six read-ahead checksnpm run test:focused -- tests/boundary/mcp/ghidraDecompileDeadlineLifetime.test.ts tests/boundary/mcp/pseudocodeDeliveryMcp.test.ts tests/boundary/cli/analysisViewCli.test.ts— 41 tests passedrea decompile-alland MCP sessions against Ghidra 12.2 — results abovenpm run check:fast— typecheck, lint and architecture guards passednpx oxfmt --checkon the changed files — passedCompatibility, safety, and release
Author readiness
Human owner: @morluto
Review follow-up
ghidra.decompile_max_payload_mibis set.scripts/verify-real-ghidra-decompiler-failure.mjscovers both bridge fixes and passes on Ghidra 12.2.