GitNexus/gitnexus/bench/java-overload-resolution/README.md
Gergő Magyar ea97d6db89
fix(cache): reuse unchanged files across chunk boundaries (#3856)
* fix(cache): reuse unchanged files across chunks

Key parser facts and scopes per file while retaining batched workers
and compressed pack storage. Preserve staged repairs and recovery.

Fixes #3849

* ci: gate parse cache speed and memory

Compare fresh baseline and candidate processes on both corpora.
Require paired speed and RSS improvements, graph equality, and
bounded phase regressions; retain measure.json and failed trials.

* perf(cache): reduce result restore overhead

Batch adjacent pack reads within bounded windows. Avoid duplicate
validation and oversized decompression buffers while preserving
binding, checksum, output-limit, and corruption checks.

* ci: keep checks active for stacked cache PR

Allow PRs targeting fix/3852-root-cause to run the test and performance gates while the cache fix is stacked.

* fix(cache): address review feedback (#3856)

Keep optional cache failures from aborting analysis and retain immutable
packs to avoid copying every unchanged result during publication. Bind
benchmark corpus hashes unambiguously and cover worker fallback paths.

Validation: build, typechecks, focused suites, lint and smoke tests pass.
The full run passed 32,878 tests; two failures observed an overlapping
edit/build. Both complete failing files pass fresh reruns (64 tests).

* fix(cache): bound index reads and reuse checks

Check and read the same open index to prevent pathname replacement
from bypassing the size bound. Reject growth and truncation.

Require exactly one reparse in the Java edit benchmark and update
the expected cache counts while retaining semantic and scaling checks.

* perf(cache): share decoded fact strings

Deduplicate paths, IDs, and labels within each decode batch to reduce retained heap and peak RSS. Preserve valid facts and cache hits if optional interning fails.

Refs #3856

---------

Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
2026-11-10 10:52:15 +00:00

69 lines
3.8 KiB
Markdown

# Java overload and ingestion scaling
Build the package, then measure the current implementation:
```sh
npm run build
node bench/java-overload-resolution/measure.js --check --output /tmp/java-overload-check.json
```
CI runs this check in the scope-resolution benchmark job and uploads
`java-overload-resolution-benchmark.json` with that job's measurements.
`measure.js` runs three fresh-process samples at 128, 512 and 2,048 units. Each
unit adds seven methods and four calls. Two shapes exercise increasing file
counts and increasing declarations within one class. Every overload family has
two candidates; package width and inheritance depth stay fixed. The spread
shape uses separate packages with an explicit import so package-size limits
cannot silently reduce resolution work.
Each sample runs real worker parsing, scope resolution, graph construction and
database writes, with a cold cache, a warm cache and one edited source file.
The edit casts one argument to `Object`, changing exactly one selected overload.
The cold run parses every file, the warm run parses none, and the edited run
parses exactly one file in both shapes. Unchanged files must remain cache hits.
The calls cover reference specificity, widening before boxing, `var` receiver
inference through a factory call and cross-file member resolution. Expected target IDs
are generated independently of the implementation. Missing methods or calls,
incorrect targets, suppressed calls, extraction failures, incorrect cache reuse
and truncated process detection all fail the run.
The harness uses one parser worker, private temporary storage, a 128 MiB database
buffer pool, and no FTS or embeddings. It raises the file-size and process limits
to include the entire generated corpus. Each scenario forces graph reconstruction
and persistence; warm and changed scenarios reuse parse-cache chunks. Editing one
file can reparse other files in its cache chunk. This measures full graph writes,
not the separate selective database-update path.
The report includes raw samples, median wall time and process CPU time for the
whole analysis and the scope-resolution phase, main-thread heap at completion,
and process peak RSS (including workers/native memory). Peak RSS is cumulative
across the three scenarios in each child. Heap is sampled before an explicit
post-analysis collection. The built JavaScript digest identifies the measured
runtime and detects changes to it during the run.
`--check` verifies the committed corpus, call-target and cache fingerprints, then
gates every adjacent size pair and the full span. For every time and memory
metric, `(large cost / small cost) / (large size / small size)` must be at most
**1.5**. The shared gate and its quadratic-growth tests come from
`../method-declaration-facts/scaling.mjs`. Absolute baseline timings are reference
measurements, not machine-independent thresholds.
These are bounded scaling checks, not a proof of linear complexity for arbitrary
Java programs. In particular, this corpus does not increase overload-family
width, inheritance depth or generic constraint complexity. Startup and database
costs can hide growth at small sizes; the separate scope measurements and
deterministic lookup-work regression tests help expose it.
After reviewing an intentional workload or semantic change, record a baseline:
```sh
node bench/java-overload-resolution/measure.js --record --output /tmp/java-overload-record.json
```
Recording also requires all scaling and correctness checks to pass, uses at least
three samples, and is disabled in CI. `--root /path/to/built/gitnexus` selects an
isolated runtime. `--sizes 128,512,2048 --samples 1` is useful for diagnostic runs;
one-sample runs cannot record or check a baseline. Completed samples are saved
after each child so a later failure leaves usable diagnostic evidence.
The output path must not already exist; existing files and symlinks are rejected.