Skip to content

Resolver: Observe Haste names under unstable_incrementalResolution - #2232

Closed
robhogan wants to merge 1 commit into
pr2231from
pr2232
Closed

robhogan wants to merge 1 commit into
pr2231from
pr2232

Conversation

@robhogan

Copy link
Copy Markdown
Collaborator

Context

#1949 records what a resolution looks up in the file map, but Haste lookups aren't paths. With allowHaste, every bare specifier is looked up by name in the Haste map, and a module of that name appearing later changes the result. So the name needs observing whether or not it was found.

This change

This adds haste to ResolutionObservations. It's the bare name, not the platform, because HastePlugin falls back from platform to native to generic and a change to any of those can change the answer:

if (supportsNativePlatform) {
this.#assertNoDuplicates(
name,
H.NATIVE_PLATFORM,
supportsNativePlatform,
dupMap.get(H.NATIVE_PLATFORM),
);
if (map[H.NATIVE_PLATFORM]) {
return map[H.NATIVE_PLATFORM];
}
}
this.#assertNoDuplicates(
name,
H.GENERIC_PLATFORM,
supportsNativePlatform,
dupMap.get(H.GENERIC_PLATFORM),
);
if (map[H.GENERIC_PLATFORM]) {
return map[H.GENERIC_PLATFORM];
}

It's free in the default config, where nothing can have a Haste name and the map is empty. Otherwise the set is created on the first name recorded, since most resolutions are relative imports that never consult Haste. No measurable cost either way.

Invalidating from these needs HastePlugin to report which names a change rebound, which is #1953.

Benchmark

AI-driven, flag on in all columns, 7 interleaved rounds. Everything is within half a percent, inside the run-to-run spread.

scenario #1949 this PR #1949, Haste enabled this PR, Haste enabled
first build (ms) 112.4 111.8 111.2 110.6
rebuild, nothing changed (ms) 7.75 7.78 7.81 7.79
after a source edit, the edited module's dependencies (µs) 177 168 170 172
after a package.json change, re-resolving everything (ms) 93.2 93.2 93.6 94.1
heap retained after resolving (MB) 18.8 18.8 19.1

Changelog: Internal

Test plan

New tests cover Haste inert, a name found and not found, a deep import, and a relative import.

Benchmark app: the synthetic RN 0.87 app described in #1945 (2.8k-module bundle, 34k-file file map). "Haste enabled" sets enableGlobalPackages: true, which gives its first-party packages Haste names.

## Context

#1949 records what a resolution looks up in the file map, but Haste lookups aren't paths. With `allowHaste`, every bare specifier is looked up by name in the Haste map, and a module of that name appearing later changes the result. So the name needs observing whether or not it was found.

## This change

This adds `haste` to `ResolutionObservations`. It's the bare name, not the platform, because `HastePlugin` falls back from platform to `native` to generic and a change to any of those can change the answer:

https://github.com/react/metro/blob/6dbe97956af0f66f7a1d88014ba0b784a4a4d893/packages/metro-file-map/src/plugins/HastePlugin.js#L194-L213

It's free in the default config, where nothing can have a Haste name and the map is empty. Otherwise the set is created on the first name recorded, since most resolutions are relative imports that never consult Haste. No measurable cost either way.

Invalidating from these needs `HastePlugin` to report which names a change rebound, which is #1953.

## Benchmark

AI-driven, flag on in all columns, 7 interleaved rounds. Everything is within half a percent, inside the run-to-run spread.

| scenario | #1949 | this PR | #1949, Haste enabled | this PR, Haste enabled |
|---|---|---|---|---|
| first build (ms) | 112.4 | 111.8 | 111.2 | 110.6 |
| rebuild, nothing changed (ms) | 7.75 | 7.78 | 7.81 | 7.79 |
| after a source edit, the edited module's dependencies (µs) | 177 | 168 | 170 | 172 |
| after a `package.json` change, re-resolving everything (ms) | 93.2 | 93.2 | 93.6 | 94.1 |
| heap retained after resolving (MB) | 18.8 | 18.8 | | 19.1 |

Changelog: Internal

## Test plan

New tests cover Haste inert, a name found and not found, a deep import, and a relative import.

Benchmark app: the synthetic RN 0.87 app described in #1945 (2.8k-module bundle, 34k-file file map). "Haste enabled" sets `enableGlobalPackages: true`, which gives its first-party packages Haste names.
@robhogan
robhogan added this pull request to stack #2234 November 16, 2026 16:17
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Nov 16, 2026
@robhogan
robhogan removed this pull request from stack #2234 November 16, 2026 16:18
@robhogan
robhogan deleted the branch pr2231 November 16, 2026 16:18
@robhogan robhogan closed this Nov 16, 2026
@robhogan

Copy link
Copy Markdown
Collaborator Author

Opened by mistake, duplicate of #1952

@robhogan
robhogan deleted the pr2232 branch November 16, 2026 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant