GitNexus/gitnexus/bench/scope-resolution/README.md
Gergő Magyar 50228e11ab
Some checks are pending
CodeQL / Analyze (javascript-typescript) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
Gitleaks / gitleaks (push) Waiting to run
Publish / Classify release event (push) Waiting to run
Publish / RC guard (marker + release-PR skip) (push) Blocked by required conditions
Publish / ci (push) Blocked by required conditions
Publish / Publish to npm (push) Blocked by required conditions
Publish / Build & Push RC Docker images (push) Blocked by required conditions
Scorecard / Scorecard analysis (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-cli) (push) Waiting to run
Trivy Image Scan / Trivy (gitnexus-web) (push) Waiting to run
fix(java): match javac resolution and move fixtures into conformance (#4056)
* test(java): compare overload resolution with javac in CI

* test(conformance): share call resolution reports across tools

* test(java): cover the overload conversion matrix with javac (#4057)

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>

* test(java): run Java-backed fixtures in dedicated CI shards

* test(java): replace handwritten resolution cases with javac comparisons

* test(java): compare lambda and receiver fixtures against javac

* fix(ci): restore Java test evidence and use locked toolchain commands

* test(skills): fail incomplete CLI generation checks (#4056)

* test(java): compare method references with javac

* fix(java): resolve qualified bases and static wildcard overloads

* test(java): preserve declared dollar names in compiler comparisons

* fix(java): preserve distinct call targets for colliding type names

* fix(conformance): resolve private nested bases and retain overload selections

* fix(java): distinguish variadic overloads in the published graph

* fix(java): match javac for nested types, imports and initializer calls

* Move Java fixture testing out of Vitest and into compiler conformance

* Verify Java graph endpoints and leave call selection to javac

* Match javac for annotated bases and legal static imports

* Resolve nested Java member types and clean up failed conformance fixtures

* Preserve qualified Java bases across unrelated static wildcard imports

* test(java): run inline source fixtures in compiler conformance

* test(conformance): check fetch callers, lexical bindings and cleanup

* test(java): move virtual source and text fixtures into conformance

* fix(java): resolve imported member types and qualified base collisions

* Match javac constructor overloads and preserve Java conformance coverage

* Compare recovered Java inheritance with javac in the conformance runner

* Run the Java query compilation smoke test in native conformance

* Clarify Java conformance expectations and check populated suites

* Write javac conformance records as UTF-8 on Windows

* Compile the Java conformance tools for SonarCloud analysis

* Compare Java method implementation edges with javac

* Resolve fixture writers and inherited Java methods in their lexical context

* Resolve qualified Java bases through their accessible type members

* Match local qualified Java bases and bounded varargs identities to javac

* Match Java call resolution to javac across the conformance corpus

Preserve generic declaration identity, follow nested call results, and type lambda aliases and enhanced-loop variables in their declaration scopes. Report proven JDK call targets without creating workspace edges. Compare every selected source and binary call against javac and remove the twelve mismatch lists.

* Compare Java recovery targets as sets and check empty destination addresses

Keep repeated uses of the same declaration equivalent across graph producers while detecting missing and extra targets. Check raw destination addresses and document the source and classpath inputs to the compiler comparison.

* Avoid extra native parent walks while capturing Java call facts

Index lambda origins by spelling before walking lexical scopes, and only check value shadowing for qualifiers rooted in an identifier. This restores the capture traversal budget for anonymous classes while preserving javac call targets.

* Refresh the Java capture fingerprint for corrected fixture comments

The module captures include the revised comments and the following declarations move to earlier lines. Both emitters produce the same 4,288 capture groups when given the same fixture revision.

* Preserve Java conformance assertions and use trusted fixture paths

Use explicit canonical sort orders, require missing evidence to fail assertions, and keep pending query results in the replay cache. Resolve the Git executable independently of the test repository and isolate the Spring workspace per test.

* Resolve inherited Java members through the scoped superclass

* Reuse validated analyzer build hashes for parser cache identity

* Resolve SonarCloud findings in Java resolution and compiler conformance

* Align Java compiler tool packages and pin benchmark baselines to the tested merge

* Honor wildcard method families and fixture ownership in Java conformance

* fix(java): resolve inherited and annotation member types against javac

Keep workspace links tied to import declarations and compare Java varargs overloads through comments. Make generated-project selection, method metadata checks and Java fixture ownership explicit in conformance.

* fix(java): resolve bounded and imported bases during dispatch

Keep the type selected from a qualified heritage clause available during overload resolution. Compare annotated bounds, inherited static imports, and String.valueOf arguments directly with javac. Detect Java fixture paths on either side of a filesystem rename.

* Conform Java method visibility and wildcard lambda bounds to javac

Compare method access at source positions, recognize CommonJS fixture reads, and preserve diagnostics when native conformance setup fails.

* Match javac for qualified member overloads and selective call diagnostics

* Track reassigned Java fixture paths at their point of use

* Respect Java visibility and Node path semantics in conformance checks

* Align Java graph benchmarks with compiler-verified visibility

* Record the public Java record accessor in the mixed-provider benchmark

* Address remaining Java conformance analysis findings

Keep repository import scans sequential, simplify Java header and overload resolution, and reuse Spring conformance measurements. Preserve compiler comparison assertions and emitted fixture contents.

* Match javac on nested binary names, null factories and recovered calls

Preserve the qualified annotation target in workspace links. Compare valid and invalid arguments separately so an attributed recovery symbol cannot mask a failed invocation.

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-25 18:03:32 +00:00

147 lines
8.5 KiB
Markdown

# Scope-resolution measurements
Run from `gitnexus/` after `npm run build`:
```sh
node --import tsx bench/scope-resolution/measure.mts --check --output /tmp/scope-resolution.json
```
CI runs every language in both `SupportedLanguages` and `SCOPE_RESOLVERS`, serially.
Missing corpus or resolver entries fail the inventory check. Each language has
100- and 1,000-entity workloads with 20 generated members or procedures per entity,
plus callers and helpers. Rust also needs a root
module file; Objective-C has a header and implementation per entity. Java adds an
isolated producer file and exercises transitive factory returns and repeated
unreachable return-name lookups. Swift uses same-module visibility; COBOL exercises
program references and procedure pointers. R sources the preceding file and calls
through an R6 instance; the second call of its chain stays unresolved, because R6
method results carry no type. Other arms import the preceding file and call through its
return value. These generated sources exercise the analyzer; they are not builds
or representative application benchmarks.
Every sample runs in a fresh process through real parsing with one worker and the
production scope-resolution pass. COBOL also runs its standalone structural parser.
Configuration files are written to a temporary workspace and loaded through the resolver's normal
configuration hook. No production heap, file-count, or propagation limit is imposed.
The JSON artifact and GitHub job summary report the median of three samples:
- Parsing and scope-resolution wall time separately.
- JavaScript heap immediately after parsing and after resolution. These are endpoint
samples, not peak heap or retained heap after garbage collection.
- Process peak RSS through resolution, including worker memory. This is the OS
high-water mark, not a timer that can miss synchronous allocation spikes.
- Module and total type-binding counts, node/edge counts, and cross-file calls.
- An order-independent fingerprint of node identities and complete relationship
endpoints, types, confidence and reasons. Equal counts alone are insufficient.
The check requires every source to reach scope resolution, nonempty declarations
and cross-file calls, identical graph fingerprints between trials, and equality
with committed graph baselines. Type-binding counts must be deterministic and must
not exceed the recorded counts; reductions are allowed. These measured allocation
budgets catch redundant table growth even when the graph stays identical. Runtime
and heap/RSS are measurements, without uncalibrated
absolute performance thresholds. Compare the same workload on the same machine
before choosing an optimization.
For a smaller diagnostic run:
```sh
node --import tsx bench/scope-resolution/measure.mts --language java --sizes 10,100 --methods 20 --repetitions 3
```
To establish baselines after reviewing a fixture, semantic, or allocation change,
run the default all-language workload with `--record` instead of `--check` and inspect
`baselines.json`. CI never records or accepts a new baseline automatically.
## Finalization import-miss probe
To reproduce the allocation trigger isolated while investigating #3695:
```sh
node --expose-gc --import tsx bench/scope-resolution/finalize-miss.mts 500
```
Run in fresh processes on each revision after building. This constructs 500
files with chained wildcard imports, a terminal module with an unresolved external
wildcard import, and a consumer importing a missing name from that terminal module.
The missing name cannot be supplied by re-exports, so it should not trigger
construction of the unrelated chain's
transitive export tables. The JSON reports finalization time, endpoint heap
growth, process peak RSS, and a fingerprint of all finalized imports, bindings,
SCCs and statistics. It is a synthetic finalizer workload, not a full Java
indexing run or a reproduction of the reporter's private repository.
For a real indexing run, the existing `GITNEXUS_DEBUG_HEAP=1` and
`GITNEXUS_HEAP_PROBE_FILE` settings now include `sr-finalize-*` markers for input
preparation, import-target resolution, SCCs, ambiguity checks, transitive exports
(only if requested), linking, wildcard expansion, bindings and workspace indexes.
`sr-extract-start` precedes `sr-post-nodeLookup`; a last `sr-post-nodeLookup`
marker therefore points into finalization after extraction.
## Post-resolution memory probes (#3695)
```sh
node --expose-gc --import tsx bench/scope-resolution/call-signature-memory.mts 500000
GITNEXUS_DEBUG_HEAP=1 node --import tsx bench/scope-resolution/dense-java.mts 300 20 10
node --expose-gc --import tsx bench/scope-resolution/wildcard-java.mts 700 700
```
`wildcard-java.mts` has 700 files that each write `import big.*;` over a 700-file
package and use one of its types: 490,000 (importer, package file) pairs, 700
`IMPORTS` edges. With `--check` it requires that no wildcard import is stored as
one edge per package file, that every importer still reaches every package file,
the reviewed graph fingerprint, and at most 16 MiB of heap retained by the pass.
The pass retains about 4 MiB when on-demand imports are stored as groups and about
54 MiB with one edge per package file; set `GITNEXUS_DISABLE_IMPORT_GROUPS=1`
(without `--check`) to measure the second form on the same build. This is one
synthetic shape, not a representative repository.
`--closure` adds an enum whose file has `import big.*;` and a static import of
one of its constants. Finalize does not find that name among the enum file's
top-level declarations, so it builds re-export closures for the workspace. Retained heap stays near
4 MiB either way; what the build holds while it runs shows only in the heap the
process needs. CI therefore runs this shape under `--max-old-space-size=180`:
the pass completes in 160 MB (not in 150 MB), and did not complete in 200 MB
when the build wrote out one draft per (importer, package file) pair. The
closure tables themselves are still one entry per importer and imported name.
CI runs these probes once with `--check` in the existing
`scope-resolution-benchmark` job, alongside its all-language measurements.
The ordinary-call check rejects any retained signatures. The dense Java check
requires the default 300/20/10 workload and its reviewed full graph fingerprint
below. Heap and timing remain measurements, without absolute thresholds.
Both outputs join the existing `scope-resolution-benchmark` artifact: the
collector's JSON and dense Java's log, including `sr-emit-*` heap checkpoints.
Omit `--check` for comparisons against older revisions or custom workloads.
The first probe isolates ordinary calls with no indirect-call facts. Previously
the deferred-call collector retained a signature object and position key for
every call even though none could be consumed. At 500,000 calls, three fresh
processes measured a median 90.29 MiB retained overhead before the change and
0.08 MiB afterward. With `--max-old-space-size=160`, the old collector exhausted
the heap (exit 134); the updated collector completed. Input records remain live
through both measurements. This measures one allocation source, not total
indexing memory.
The second probe uses real worker parsing and scope resolution on generated
Java: 300 files, 20 methods per file, 10 receiver calls per method. It reports
per-stage heap samples and a fingerprint of complete nodes and relationships.
Before and after the change it produced 66,300 nodes and 126,600 relationships,
with fingerprint `3209302e91e7023328464540ec7d0ac72ac03bf49fa73303817a56ed3d415ef5`.
The current fingerprint is `7ff03cec3bbfd427bb232bc75fcebc19b37f097aa6d1e7b4e1a5fbf0d00197b2`.
The change marks all 60,000 method-local variables as unexported. All 60,000
call edges match the caller and target declarations reported by javac.
It uses the in-memory graph helper, so its RSS is not a measurement of the CLI's
streaming graph sink. Calls pass `null` to match each receiver's parameter type;
the 300-file workload compiles with `javac --release 17`. The probe measures
analysis and does not execute the generated Java.
`GITNEXUS_DEBUG_HEAP=1` now adds `sr-emit-*` checkpoints after receiver calls,
free calls, replay, references, property passes, callable flow, imports and
provider hooks, including elapsed emit time and graph counts. `sr-post-resolve`
marks the end of the initial registry lookup only; substantial resolution still
follows it. These markers distinguish that work on the next reporter run.
The private repository's complete OOM has not been reproduced by these probes.
For the import-emission memory benchmark, see [its README](../import-emission/README.md).