Skip to content

perf(dotnet): push down native boundary and member selection predicates - #13317

Merged
morluto merged 3 commits into
mainfrom
perf/dotnet-managed-predicate-pushdown
Nov 22, 2026
Merged

morluto merged 3 commits into
mainfrom
perf/dotnet-managed-predicate-pushdown

Conversation

@morluto

@morluto morluto commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Summary

Pushes predicates down into .NET metadata table decoding so native-boundary analysis, selected-type inspection, and #US overflow recovery avoid decoding unreferenced members or re-running full metadata scans:

  1. Native boundary predicate pushdown (ManagedNativeBoundaryInspector.ts, ManagedNativeBoundaryHelpers.ts):
    • Retains readBoundaryInventory (inventory.issues diagnostics across CustomAttribute, ManifestResource, AssemblyRef, Assembly, Module, cli.resources).
    • Scans ImplMap (table 28) first (scanImplMaps) to collect imports, ImplMap issues, referencedFieldRows, and referencedMethodRows, decodes only referenced Field names (readReferencedFieldNames), and scans only the fixed-width 4-byte ImplFlags + Flags word at MethodDef +4 (scanNativeMethods, mask 0x2000_1007) so non-boundary Field and MethodDef rows are never decoded.
  2. Single-pass #US budget overflow preservation (ManagedMemberInspector.ts):
    • Builds baseInspection (user_strings: null) before parseUserStrings, and catches ManagedRepresentationFailure via withoutUserStrings(baseInspection, cause) rather than re-running inspectManagedMembersBytes(..., { userStrings: false }). The completed report is validated once.
  3. Constant declaration coverage. Selected and complete inspections share the same order-independent declaration index and decode blobs only for examined fields.
  4. Monotonic FieldList / MethodList interval iteration (ManagedMemberRows.ts):
    • Iterates selected [start, end) intervals directly and resolves member declaring types via binary search over ranges when selected !== null and pointer tables (FieldPtr/MethodPtr) are absent and monotonic (falling back cleanly to memberDeclaringTypeRowLookup otherwise).

Problem and expected behavior

  • inspectManagedNativeBoundariesBytes materialized full Field and MethodDef maps (89,775 rows on capacity fixtures) even when only P/Invoke/unmanaged methods were requested, parseFields/parseMethods allocated full ownership Uint32Array maps under selection, and #US budget overflow re-ran the full metadata inspection from scratch.
  • Expected behavior: identical inventory.issues, native boundaries, field constants, member ownership, and #US omission diagnostics while skipping unreferenced rows cleanly.

Change and scope

  • Modified ManagedNativeBoundaryInspector.ts, ManagedNativeBoundaryHelpers.ts, ManagedMemberInspector.ts, ManagedMemberRows.ts, and 4 unit test files (ManagedNativeBoundaryInspector.test.ts, ManagedMemberInspector.test.ts, ManagedFieldConstants.test.ts, ManagedMemberOwnership.test.ts).

Follow the contribution scope.
Not applicable (internal .NET metadata reader optimizations within existing read-only contracts).

Contract and boundary impact

  • Semantic owner and earliest changed stage: ManagedNativeBoundaryInspector, ManagedMemberInspector and ManagedMemberRows (ECMA-335 table readers).
  • Contribution scope fit and linked maintainer decision: not applicable.
  • CLI and MCP/tool-catalog contract: none.
  • Provider, bridge, target-format, or platform compatibility: preserved (FieldPtr/MethodPtr indirect layouts continue to use the established fallback, and Constant declaration order is preserved).
  • Evidence, artifact, provenance, or reconstruction contract: preserved (identical inventory.issues, readManagedMetadataInventory diagnostics, and withoutUserStrings partial omission state).
  • Target selection, authority, upstream behavior, and cleanup details: not applicable.
  • Generated metadata (docs/public/product-catalog.json), 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:
    • ManagedNativeBoundaryInspector.test.ts: native boundary predicate pushdown.
    • ManagedMemberInspector.test.ts: user string capacity overflow preserves decoded members.
    • ManagedFieldConstants.test.ts: selected defaults and duplicate declarations survive non-monotonic Constant tables.
    • ManagedMemberOwnership.test.ts: selected FieldList and MethodList interval iteration.
  • Base reproduction or other evidence (origin/main 264c398c0d vs 0bcdb19378, Apple M5 arm64, Node v24.22.1):
    • inspectManagedNativeBoundariesBytes (buildManagedMemberSelectionCapacityFixture, 9,409 TypeDefs / 40,037 Fields / 49,738 MethodDefs / 58,698 CustomAttributes): cold 181.82 ms -> 92.84 ms, warm median 132.64 ms -> 69.01 ms; non-boundary rows decoded 89,775 -> 0; tight maxRepresentationBytes: 40_000_000 moves "unavailable" -> "complete".
    • parseFields + parseMethods (selected = Set(["0x02000001"])): cold 15.02 ms -> 5.10 ms, warm median 4.38 ms -> 0.57 ms (Uint32Array ownership allocations 4 -> 0).
    • inspectManagedMembersBytes #US overflow (500 methods): cold 46.89 ms -> 29.50 ms, warm median 36.05 ms -> 21.46 ms (readManagedMetadataInventory passes 2 -> 1).
  • User-visible CLI/MCP output (if applicable): identical schemas; tight-budget native boundary calls now succeed where full decoding previously overflowed.
  • Remaining proof gaps: benchmarks and tests use constructed synthetic PE fixtures (ManagedPe.fixture.ts, managedMemberCapacity.ts, scripts/fixtures/managed/pe.mjs); external real-world .dll binaries were not benchmarked locally.

For evidence-bearing changes:

  • 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 format:check (8,602 files) — passed
  • npm run check:fast (typecheck, lint, verify:architecture-guards across 2,944 source files) — passed
  • npm run test:local (30 unit/conformance/composition suites across src/dotnet/*.test.ts, src/domain/managed/*.test.ts, managedNativeVerification.test.ts, managedApplicationGraph.test.ts) — 30/30 files, 733/733 passed
  • npm run build:cached & npm run test:focused (8 boundary/MCP/acceptance suites: managedDirectAnalysis, managedStaticProvider, managedFieldConstantsComparison, managedMcp, managedFieldConstantsMcp, managedMemberRecovery, managedSelectedScope, managedMemberPointers) — 8/8 files, 34/34 passed
  • npm run knip:production — exited 0 (advisory report only)

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: Node v24.22.1 unit, conformance, MCP boundary, and acceptance suites on darwin with synthetic ECMA-335 PE fixtures.
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: all bounds, FieldPtr/MethodPtr indirection, and monotonic-order fallbacks are checked prior to fast-path indexing; budget reservations remain accounted cleanly.

Author readiness

Human owner:

  • 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.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 22, 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-22T08:26:46.995568Z a5c2832 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: 0bcdb19378

ℹ️ 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 src/dotnet/ManagedFieldConstants.ts Resolved
@greptile-apps

greptile-apps Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issue remains.

Summary

The latest change moves #US overflow recovery into inspectManagedMembersBytes without changing its behavior.

  • Native-boundary reports skip decoding unrelated member rows.
  • Selected member inspections walk only the chosen types’ usable row ranges.
  • User-string overflow keeps member results without repeating the inspection.

Reviews (3) · Last reviewed commit: "fix(dotnet): preserve readonly member dr..." · Reviewed by Greptile

Comment thread src/dotnet/ManagedFieldConstants.ts Resolved
Comment thread src/dotnet/ManagedMemberInspector.ts Resolved
@morluto morluto changed the title perf(dotnet): push down native boundary, selection, Constant, and #US overflow predicates perf(dotnet): push down native boundary and member selection predicates Nov 22, 2026
@morluto
morluto enabled auto-merge (squash) November 22, 2026 08:43
@morluto
morluto merged commit e0d8cc9 into main Nov 22, 2026
40 checks passed
@morluto
morluto deleted the perf/dotnet-managed-predicate-pushdown branch November 22, 2026 08:45
Davmunrey added a commit to Davmunrey/rea that referenced this pull request Nov 22, 2026
Main split field and method decoding into decodeFieldRow and
decodeMethodRow with per-call contexts (morluto#13317) and rewrote the field
constant budget test (morluto#13365). Carry the parameter defaults onto that
shape: the inspection's shared Constant reader goes into parseFields and
parseMethods, the field context calls it with the Field table, and the
method context holds the Param default reader so both the full scan and
the selected-interval path report parameter_defaults. The budget test
now calls the shared reader with the Field table.
@morluto morluto added area: native Native analysis and decompilation, including Ghidra, IDA, and Hopper analysis behavior performance Performance regressions, scaling limits, and bounded-resource work labels Nov 22, 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.

1 participant