Skip to content

perf(javascript): skip nested callables during fingerprint traversal - #1871

Merged
morluto merged 1 commit into
morluto:mainfrom
cyanseek:codex/skip-nested-fingerprint-traversal
Oct 11, 2026
Merged

morluto merged 1 commit into
morluto:mainfrom
cyanseek:codex/skip-nested-fingerprint-traversal

Conversation

@cyanseek

Copy link
Copy Markdown
Contributor

Summary

Skip nested callable subtrees while collecting a function's syntax fingerprint. Related to #1065 and the cooperative traversal introduced in #1545.

Problem and expected behavior

fingerprintSyntaxSteps walks each callable's complete subtree, then ignores nodes belonging to nested callables. A deeply nested function body is therefore visited once for every enclosing function even though it contributes tokens only to its own fingerprint. Fingerprint collection should visit the syntax owned by the current callable while preserving every existing fingerprint.

Change and scope

Add an optional child-subtree skip predicate to the shared AST traversal. Fingerprints use it at nested callable boundaries, replacing the local callable stack. The root is still visited; skipped children receive neither enter nor exit callbacks. Traversal order, ancestor snapshots, and cooperative checks remain intact. Each nested callable still gets its own fingerprint in the existing outer collection loop.

Contract and boundary impact

  • Semantic owner: domain JavaScript function fingerprint collection.
  • CLI/MCP and tool catalog: unchanged contracts and complete output.
  • Provider/platform compatibility: shared static JavaScript analysis; no provider changes.
  • Evidence/provenance/reconstruction: unchanged IDs, fingerprint components, source locations, coverage, and unknowns.
  • Process/authorization/cleanup: no change.
  • Generated metadata/package/installation: no change.

Evidence and regression coverage

  • Added behavior tests for skipped-subtree sibling ancestry/exit callbacks and fingerprint ownership across nested functions, object methods, class methods, and subsequent outer statements.
  • Five alternating baseline/candidate pairs on native Windows, Node 24.18.0, Ryzen 7 9700X, with a 1,536 MiB Node heap limit. A generated 400-level nested-function input (27,952 bytes) reduced median semantic analysis from 297.65 to 113.61 ms. Complete CLI process wall time, including full output, changed from 2,536.80 to 2,332.95 ms; median within-pair reduction was 191.94 ms. These are measurements of this generated stress input.
  • Complete serialized IR, normalized results, Evidence IDs, and complete Evidence hashes matched across all ten runs of each of four inputs: generated 160/400-level nesting, the complete @babel/[email protected] lib/index.js, and the complete [email protected] UMD file. The published-package sources provide semantic parity coverage.
  • Actual Windows stdio MCP preserved the same complete Evidence as CLI: the smaller inputs passed inline text/structured parity; the 400-level input retained its existing typed transport constraint and successfully exported the complete record. Subsequent ping and analysis passed, and clients/transports were closed.
  • Performance comparison base: 069308b; final patch integrated with d3e9ee5, followed by static, domain, focused, and MCP parity verification.
Generated input
const depth = 400;
const source = Array.from({ length: depth }, (_, i) =>
  `function wrap${i}(value) { const tag${i} = ${i};`
).join('\n') + '\nreturn value;\n' +
Array.from({ length: depth - 1 }, (_, i) =>
  `} return wrap${depth - i - 1}(value);`
).join('\n') + '\n}';

Save as the only main.js in an input directory. Run rea analyze-javascript-application <directory> --artifact-format directory --format json with stdout fully consumed. Semantic timing calls analyzeJavaScriptSemantics(source) separately, excluding result serialization.

  • Observed, derived, and inferred claims remain distinguishable.
  • Artifact identity, source provenance, and failed attempts remain preserved.
  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run check — passed, including typecheck, lint/module boundaries, formatting, Knip, metadata, and architecture guards.
  • npm run build:cached — passed.
  • node node_modules/vitest/vitest.mjs run --project domain src/domain/javascript --maxWorkers=2 — 844 passed across 44 files.
  • npm run test:focused -- the two changed test files, javascriptApplicationCancellation.test.ts, javascriptAnalysisCancellation.test.ts, javascriptCancellationCli.test.ts, and packageSubpathsCli.test.ts — 34 passed; two POSIX SIGINT cases use the suite's existing Windows skip. SDK cancellation/recovery and native Windows CLI/MCP cases passed.
  • Complete CLI/stdio MCP comparisons described above — passed.
  • git diff --check and commit hooks — passed.

Compatibility, safety, and release

No breaking change, migration, or package metadata change. Verification covers native Windows static JavaScript workflows. Hopper/Ghidra/browser execution is outside this change; no new engine or runtime-execution capability is claimed.

Review checklist

  • Concrete problem, focused outcome, and Conventional Commit title.
  • Related work linked; this does not close the broader [Feature] Roadmap: improve MCP usability and performance under bounded resources #1065 roadmap.
  • Tests cover ownership, traversal behavior, and existing cancellation/recovery boundaries.
  • Existing contracts and generated metadata remain unchanged.
  • Final diff checked for secrets, unrelated changes, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T15:02:56.071059Z bcf3819 PR opened
ℹ️ 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.

@morluto
morluto merged commit 097f0d5 into morluto:main Oct 11, 2026
25 of 26 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 11, 2026
3 tasks done
@morluto

morluto commented Oct 11, 2026

Copy link
Copy Markdown
Owner

Thanks, @cyanseek, for teaching the shared AST walker to skip child subtrees and using that at nested-callable boundaries. A parent fingerprint no longer re-walks nested function bodies, while each nested callable still gets its own fingerprint; your parity checks cover generated nesting and complete published parser sources.

@morluto morluto added performance Performance regressions, scaling limits, and bounded-resource work area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants