On every resolve that descends through a description file, plugins were
re-walking the same `package.json` content to answer questions whose
inputs are stable: does this file have an exports/imports/alias field,
what's the main module, does a conditional mapping resolve to the same
target under the resolver's fixed condition set. Add narrow caches that
key on stable object references (parsed JSON content, conditional
mapping objects, conditionNames Sets) so repeat resolves against the
same package skip the lookup work.
* `util/entrypoints.js`: memoize `conditionalMapping(mapping, conditionNames)`
in a `WeakMap<ConditionalMapping, WeakMap<Set<string>, ...>>`. Uses a
sentinel for `null` results so the hit path is a single `get()`.
* `ExportsFieldPlugin`/`ImportsFieldPlugin`: cache `null` in the existing
per-content processor WeakMap for description files that have no
exports/imports field, skipping the `DescriptionFileUtils.getField`
walk on subsequent resolves. Builds the processor inside the existing
try/catch so malformed fields still surface their error.
* `MainFieldPlugin`: cache the fully-resolved `mainModule` string (with
forceRelative already applied) per content, with a `NO_MAIN` sentinel
for packages whose main field is absent / "." / "./".
* `AliasFieldPlugin`: cache the resolved alias-map object per content
(or a sentinel when the field isn't a valid alias config).
* `SelfReferencePlugin`: cache the `"name"` string per content when
self-reference applies (or a sentinel when it can't).
Benchmarks (--no-opt, local):
realistic-midsize warm: 723 ops/s -> ~763 ops/s (+5.5%)
realistic-midsize cold: 34.0 -> ~34.7 (~+2%)
exports-patterns-many: 507 -> 526 (+3.8%)
mixed-conditions: 2718 -> 2730-2765 (~+1%)
self-reference: 2233 -> 2265 (+1.4%)
exports-field (warm): ~1240 -> ~1230 (within noise)
https://claude.ai/code/session_01JM6aPUSLLfmEdtxeffMAiZ
On every resolve that descends through a description file, plugins were
re-walking the same
package.jsoncontent to answer questions whoseinputs are stable: does this file have an exports/imports/alias field,
what's the main module, does a conditional mapping resolve to the same
target under the resolver's fixed condition set. Add narrow caches that
key on stable object references (parsed JSON content, conditional
mapping objects, conditionNames Sets) so repeat resolves against the
same package skip the lookup work.
util/entrypoints.js: memoizeconditionalMapping(mapping, conditionNames)in a
WeakMap<ConditionalMapping, WeakMap<Set<string>, ...>>. Uses asentinel for
nullresults so the hit path is a singleget().ExportsFieldPlugin/ImportsFieldPlugin: cachenullin the existingper-content processor WeakMap for description files that have no
exports/imports field, skipping the
DescriptionFileUtils.getFieldwalk on subsequent resolves. Builds the processor inside the existing
try/catch so malformed fields still surface their error.
MainFieldPlugin: cache the fully-resolvedmainModulestring (withforceRelative already applied) per content, with a
NO_MAINsentinelfor packages whose main field is absent / "." / "./".
AliasFieldPlugin: cache the resolved alias-map object per content(or a sentinel when the field isn't a valid alias config).
SelfReferencePlugin: cache the"name"string per content whenself-reference applies (or a sentinel when it can't).
Benchmarks (--no-opt, local):
realistic-midsize warm: 723 ops/s ->
763 ops/s (+5.5%)+1%)realistic-midsize cold: 34.0 ->
34.7 (+2%)exports-patterns-many: 507 -> 526 (+3.8%)
mixed-conditions: 2718 -> 2730-2765 (
self-reference: 2233 -> 2265 (+1.4%)
exports-field (warm): ~1240 -> ~1230 (within noise)
https://claude.ai/code/session_01JM6aPUSLLfmEdtxeffMAiZ