Conversation
# Conflicts: # tests/npm_metadata/results/README.md
Cache repeated npm module loader filesystem work
…-current Reduce stripped ESM module load latency
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Real npm and TypeScript workloads exposed avoidable work in package metadata
lookups, loader realpaths, whitespace-heavy ESM scanning, large CommonJS source
preparation, source-map extraction, and syntax detection for already-known
module formats. After those owners were reduced, matched production release
measurements were added to show the remaining end-to-end gap and screen further
ideas against correctness, memory, and reproducibility gates.
What changed
bounded tracing, counter reconciliation, matched host runs, and retained
baseline/final reports
package.jsonreads only within one outer CommonJS resolutiongraph and invalidates them on guest filesystem mutation
cache with known non-symlink directory prefixes; CommonJS/ESM domains remain
separate, failures retry, Wizer starts clean, and preserve-symlink paths
bypass canonicalization
CJS-global ESM scanners; also bypasses
import.meta.mainrewriting when noimporttoken existssourceMappingURLextraction to theexisting native SWC lexer while retaining the JavaScript fallback for
non-TypeScript and VM builds
advances the direct-
eval, import-attribute, and template-expressionscanners between relevant sentinel bytes
inspection, preserving cached-TypeScript and
force_moduleprecedencereleaseprofiles to the measured local workflow, matchedfive-sample npm/TypeScript runners, memory and cache-isolation evidence, and
CI currentness selection that handles direct, squash, and two-parent merge
trees without rewriting historical reports
Wizer initialization, source maps, source preparation, format precedence,
ESM phases, and import attributes, including the regenerated DTS goldenfile
pairs; temporary instrumentation and rejected sample-level artifacts are
removed
Results
npm loader caches
The original three-sample fixed-fixture comparison reduced physical work
identically on P2 and P3:
package.jsonreadsnpm --versionnpm viewnpm ciThe later directory-prefix cache was measured against the production release
pair with five samples:
npm cinpm ciThe original and prefix-cache rows were collected in separate measurement
sessions, not as an interleaved A/B, so the wall-time deltas are directional
rather than a causal speedup estimate. A contemporaneous TypeScript pair also
drifted upward after host time was subtracted: 146/306 ms cold, 68/68 ms
repeated, and 28/154 ms incremental on P2/P3. The deterministic path-work
reductions and regression coverage remain valid independently of wall time.
Peak observed linear memory was 55.25 MiB on P2 and 48.25 MiB on P3, +4.7%
and +0.3% against the anchors and within the 10% gate. All 60 retained
host/Wasm samples succeeded; HTTP totals, npm logs, outputs, installed package
identities, lockfiles, and counters reconciled. The original cache comparison
retains measured revision
8d030cf7; the release prefix-cache reports retain831632c6.stripped ESM loading
The five-sample 64 KiB stripped-ESM phase experiment fell from
10,657.94 → 192.28 ms (P2) and 11,058.54 → 197.36 ms (P3), a 98.2%
reduction for that deliberately pathological workload. The reports retain
measured revision
7bed8b04; the refreshed uninstrumented matrix recordsprepared-ESM medians of 190.68 ms (P2) and 188.89 ms (P3).
TypeScript module loading
Native source-map extraction reduced five-sample cold
tsc --noEmitfrom19.17 → 16.72 s (P2, -12.7%) and 19.22 → 16.90 s (P3, -12.1%).
Repeated unchanged medians improved 11.2%/11.0%, warm incremental medians
improved 19.6%/17.4%, and TypeScript API import improved 30.9%/29.3%.
On top of that candidate, CommonJS source preparation reduced TypeScript API
import from 8.33 → 4.22 s (P2, -49.3%) and 8.49 → 4.22 s
(P3, -50.3%). The known-format step then reduced it from
4.22 → 3.47 s (P2, -17.9%) and 4.22 → 3.44 s (P3, -18.4%). Final
clean reports retain measured revision
dd689c8c.production release baselines
The final matched TypeScript pair records:
tsc --noEmitAgainst the practical
8 × host + 1 starget, P2/P3 miss by 0.534/0.658 scold, 1.059/0.951 s repeated, and 0.159/0.231 s incremental. Linear-memory
high water remains 145.06 MiB.
The final npm pair records 1.069/1.052 s P2/P3 cold metadata and 2.272/2.360 s
warm-tarball
npm ci. Metadata misses3 × host + 0.5 sby about 99/104 ms;cimisses2 × host + 1 sby about 776/898 ms.Each timed invocation uses a fresh QuickJS execution job. Cold rows also use a
fresh component instance, workspace, and cache. A timed warm-tarball npm job
reuses the component instance and workspace/cache populated by its untimed
seed; its memory high-water observation therefore includes the seed peak.
Remaining-cost attribution
tsc --extendedDiagnosticsattributed 4.830 s of a 5.865 sinstrumented median to TypeScript: 2.850 s checking, 1.520 s program
construction, and 0.450 s binding; the inner CLI/reporting residual was
0.780 s and the outer execution/export envelope 0.246 s
reify:unpackat 930 ms versus 93 ms on thehost and observed a 1.388 s CommonJS graph envelope across 1,727 requires;
ownership was broad, with no package reaching the 194 ms screening value
from command-time lazy loads; npm timers do not separate archive processing
from filesystem work
Temporary attribution code and raw reports were removed after their results
were summarized.
Rejected and deferred experiments
invalidation local to one runtime cannot observe host or sibling-runtime
mutations on a shared mount
by only about 1% and had no production end-to-end win; reverted
opt-levelchanges, direct bytecode dispatch, SIMD, andassertion/dump-code variants either regressed npm/TypeScript, widened tails,
or increased component size without a durable cross-workload win; reverted
moved work into the measured path without an end-to-end win
source semantics; the source-preserving version exceeded the memory gate;
the compact-span follow-up had no durable npm/cold-TypeScript benefit and
GOL-663 was canceled without retaining a fork
lstaterror delivery worsened host-adjusted warm-cimedianoverhead by about 139 ms; reverted
wasm-opt -O3produced real but modest improvements and smallercomponents, but remains deferred to GOL-661 because a supported
cross-platform integration cannot depend on an undeclared system binary
Correctness boundaries
retryable; public
node:fsrealpath is uncached; symlink-preserving modesbypass loader caches; Wizer initialization cannot populate them
no broad negative path cache remains
batched cursor targets are ASCII UTF-8 boundaries and export-parser gates are
accepted prefixes or safe supersets
.cts,.cjs,.mts, explicit package type, default-typenode_modules, andforce_moduleprecedence; ambiguous sources still use syntax detectiontypescript.js, not CLI_tsc.js; itsimport phases are attribution and not direct cold-CLI timings
changes
Evidence and validation
recovery, memory, counter, and exact-currentness validation
968657acand the production npm pair to measured source831632c6; CIvalidates each pair from a pristine worktree at that exact revision while
retaining older reports as historical evidence
incremental-seed values, and reused-instance memory high water from the raw
samples; mutation tests cover both timing summaries and aggregate memory
831632c6passes focused loader cache regressioncoverage; final TypeScript loading source
dd689c8cpassed focused units,P2/P3 module-resolution and TypeScript-runtime slices, all ten skeleton
Clippy lanes, formatting, and diff hygiene
a79a0763ed6c20ac40a3e190605200d24cd9a3cepasses exact-source TypeScript/npm report validation, selector regression
tests, focused Clippy, formatting, diff hygiene, JSON invariant checks, and
independent read-only review; complete GitHub CI run
36177926653passed all40 jobs, and the tree contains no diagnostic runtime changes or project-owned
Python files
The npm syscall reductions, stripped-ESM microbenchmark, TypeScript CLI rows,
and TypeScript API import attribution are separate claims. This PR does not
claim that arbitrary npm installs or TypeScript programs became 17–98% faster.