Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolver perf: Prefer Maps over dynamic objects for normalised exports field (5/n) #1335

Closed
wants to merge 1 commit into from

Conversation

robhogan
Copy link
Contributor

Summary:
In V8, dynamic objects (that cannot use a hidden class optimisation) are slow - Map is both more performant and generally safer.

By normalising the exports field to a Map object (once, as normalisations are cached), subsequent lookup, iteration and reduction is considerably faster, improving resolvePackageTargetFromExports around 2x.

This is an implementation detail of PackageExportsResolve.js, the normalised format is not exposed outside that module.

This brings total resolution time for RNTester down below 100ms, vs >1500ms at the beginning of this stack. (I'll allow myself a 🚀 for that).

Changelog:

 - **[Performance]**: Prefer `Map` to dynamic JS objects in package exports resolver.

Reviewed By: huntie

Differential Revision: D61850544

@facebook-github-bot facebook-github-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 Aug 27, 2024
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D61850544

…ts` field (5/n) (#1335)

Summary:
Pull Request resolved: #1335

In V8, dynamic objects (that cannot use a hidden class optimisation) are slow - `Map` is both more performant and generally safer.

By normalising the `exports` field to a `Map` object (once, as normalisations are cached), subsequent lookup, iteration and reduction is considerably faster, improving `resolvePackageTargetFromExports` around 2x.

This is an implementation detail of `PackageExportsResolve.js`, the normalised format is not exposed outside that module.

This brings total resolution time for RNTester down below 100ms, vs >1500ms at the beginning of this stack. (I'll allow myself a 🚀 for that).

Changelog:
```
 - **[Performance]**: Prefer `Map` to dynamic JS objects in package exports resolver.
```

Reviewed By: huntie

Differential Revision: D61850544
@facebook-github-bot
Copy link
Contributor

This pull request was exported from Phabricator. Differential Revision: D61850544

@facebook-github-bot
Copy link
Contributor

This pull request has been merged in 5b23317.

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. fb-exported Merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants