GitNexus/gitnexus/bench/dart-deferred-imports
Abhinav Pandey 40305b84e3
test(bench): gate Dart deferred-import resolution and its scaling (#3910)
* test(bench): gate Dart deferred-import resolution and its scaling

`import 'm.dart' deferred as p;` resolves through the same namespace path
as `as p` since #3882, except that `p.loadLibrary` is dropped at capture
time. bench/dart-deferred-imports pins what that path resolves and checks
that its cost grows linearly, following bench/ruby-gem-resolution: exact
accuracy cells and fingerprints, with ratios as the only timing gates.

The workload has N libraries that all declare the same names and one file
that imports each through a deferred prefix and calls through it M times.
The same workload spelled `as p` is the control and must hash equal.
Shapes are 16x16, 64x16 and 16x64. Capture (emitDartScopeCaptures) and
resolution (runScopeResolution over parse-worker output, replayed through
mergeChunkResults) are timed separately: min of 15 after 2 warmups, all six
workloads interleaved in one process. Peak RSS per shape comes from a fresh
process.

Gated: capture scaling along both axes and resolution scaling along uses
(1.5); resolution scaling along prefixes (2.2, because a per-Function-scope
namespace snapshot that predates #3882 makes it O(functions x prefixed
imports) for `as p` too); deferred over `as p` at 64x16 (capture 2,
resolution 1.5). On the commit before #3882 the runner fails because every
expected edge is missing.

Runs in the benchmarks (GITNEXUS_BENCH) job after the Ruby gem step.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(bench): run dart-deferred-imports --check as a 20 s CI profile

The benchmarks job has a 30-minute timeout, and its first run with this
gate took 3m10s for the full protocol, which pushed the job over the limit
(cancelled at 30 minutes, after the gate itself had passed).

--check now runs a CI profile: one process prepares all six workloads and
runs every accuracy gate unchanged (expected edges, wrong-prefix edges,
loadLibrary edges, graph equality with the `as p` control, exact counts and
fingerprints), but times only the three deferred shapes plus the `as p`
control at `large`, min of 5 after 1 warmup, interleaved. The shapes are
halved (8/32 prefixes x 16 uses, 8 x 64). It takes 18-20 s locally.

`--full` keeps the previous protocol: every workload timed, min of 15 after
2 warmups, and peak RSS from a fresh process per shape.

baseline.json is re-measured for the new shapes, with separate CI and full
measurements. The O(captures^2) negative control still fails three gates in
the CI profile (2.054 > 2, 1.573 > 1.5, 1.63 > 1.5).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

* test(bench): add Dart scaling sweep evidence

* chore(bench): remove retained Dart results

---------

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Co-authored-by: Gergo Magyar <gergomagyar0@gmail.com>
Co-authored-by: Gergő Magyar <gergomagyar@icloud.com>
2026-11-13 17:48:20 +00:00
..
baseline.json test(bench): gate Dart deferred-import resolution and its scaling (#3910) 2026-11-13 17:48:20 +00:00
measure.mjs test(bench): gate Dart deferred-import resolution and its scaling (#3910) 2026-11-13 17:48:20 +00:00
plot.py test(bench): gate Dart deferred-import resolution and its scaling (#3910) 2026-11-13 17:48:20 +00:00
README.md test(bench): gate Dart deferred-import resolution and its scaling (#3910) 2026-11-13 17:48:20 +00:00
sweep.mjs test(bench): gate Dart deferred-import resolution and its scaling (#3910) 2026-11-13 17:48:20 +00:00

Dart deferred import scaling

This benchmark checks the graph produced by Dart deferred imports and measures capture and scope resolution separately. Over the retained 16–256 sweep, capture and resolution with increasing uses are approximately linear. Resolution with increasing prefixes is superlinear for both deferred and ordinary prefixed imports.

Capture and resolution compared with linear growth

Measured scaling

The fitted exponent describes time ∝ size^exponent; 1.00 is linear. Each value is the median of three round-specific log–log fits using the median of five measured passes at each size.

Input grows Phase Deferred exponent Ordinary prefixed exponent Deferred time growth for 16× input
Prefixes, 16 uses each Capture 1.06 1.08 19.25×
Uses, 16 prefixes Capture 1.06 1.02 18.39×
Prefixes, 16 uses each Resolution 1.50 1.54 64.97×
Uses, 16 prefixes Resolution 0.98 0.94 14.81×

Using minimum timings instead of medians gives deferred exponents of 1.09, 1.06, 1.53 and 0.99 respectively. The conclusion is unchanged. The shaded bands show the observed range across rounds, not confidence intervals; these finite-range measurements do not prove asymptotic complexity.

The prefix-resolution cost comes from the existing namespace snapshot cache: each function scope collects the file's namespace imports. With P prefixes and U functions per prefix, that contributes work proportional to P² × U. The deferred-import change uses the same path as ordinary prefixed imports.

Reproduce

From gitnexus/:

npm run build
node --import tsx bench/dart-deferred-imports/measure.mjs --check
node --import tsx bench/dart-deferred-imports/sweep.mjs \
  --sizes 16,32,64,128,256 --rounds 3 --warmup 2 --reps 5 \
  --output /tmp/dart-deferred-sweep.json

The normal --check command uses the CI profile: small = 8×16, large = 32×16 and dense = 8×64, in both forms. It validates all six graphs and times four workloads with five samples after one warmup. --full --check times all six with 15 samples after two warmups and collects fresh-process peak RSS. The timing budgets are unchanged. The separate 16–256 sweep took about 24 minutes on the recorded Linux host and is not added to CI.

From eval/, render the saved data:

uv run --no-project --with matplotlib==3.11.2 python \
  ../gitnexus/bench/dart-deferred-imports/plot.py /tmp/dart-deferred-sweep.json

This produces summary.json, raw-samples.csv, series.csv, and PNG/SVG/PDF plots beside the input file. The plotter requires a completed sweep.

Measurement and correctness

  • Grow prefixes and uses separately through 16, 32, 64, 128 and 256. Keep the other dimension at 16.
  • Compare deferred and ordinary prefixed imports at every size. Each library declares the same member names, so resolution must honor the prefix.
  • Run three rounds in 60 fresh processes, sequentially. Rotate size and form order between rounds and alternate capture/resolution order within each process.
  • Prepare each cell with a real worker parse, a first resolution and an untimed capture pass. Then run two explicit warmups and retain all five measured passes: 300 measured passes per phase, plus 120 warmups.
  • Time emitDartScopeCaptures, including parsing, and runScopeResolution. Configuration loading, graph replay, correctness hashing and persistence are outside those timers.
  • Check exact workload counts and expected edges. Compare the full graph/decline fingerprint after every timed resolution with the validated initial graph, and compare deferred/prefixed fingerprints at every point. Known small/large/dense shapes must also match baseline.json.

The six-shape CI gate uses (time_large / time_small) / 4. Its prefix-resolution budget of 2.2 allows 8.8× time for 4× input. It bounds regressions at those sizes; it does not establish linearity. The original captures × prefixes negative control remained below that gate's sensitivity, as recorded in baseline.json. This sweep reports additional evidence without claiming to close that sensitivity gap.

Retained evidence

Raw samples and validated shapes and derived estimates record Linux x64, Node 22.23.3, an Intel i9-12900K, and source commit 4290f5c35fae3f8eb529e074ccb8724aceb42600. Every cell and every paired fingerprint check passed.

The compressed measured runner patch, decompressed and applied to that commit, reconstructs the exact harness bytes identified by the raw report's checksums. The shipped runner was subsequently formatted, its revision metadata made dynamic, and its baseline matching adapted to the smaller CI shapes; the sweep's timed functions and 16–256 workload are unchanged. The figure was generated from the retained raw samples, not from the PR description's earlier macOS measurements.