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

[@babel/traverse] Improve performance of mapped Visitor type #69522

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

awphi
Copy link

@awphi awphi commented May 5, 2024

Please fill in this template.

  • Use a meaningful title for the pull request. Include the name of the package modified.
  • Test the change in your own code. (Compile and run.)
  • Add or edit tests to reflect the change.
  • Follow the advice from the readme.
  • Avoid common mistakes.
  • Run pnpm test <package to test>.
  • Provide a URL to documentation or source code which provides context for the suggested changes: N/A
  • If this PR brings the type definitions up to date with a new version of the JS library, update the version number in the package.json - N/A.

Minimal repro of noticeable performance drain in this StackBlitz with this MR change applied as patch.

Before (prod):

Screenshot 2024-05-05 171002

After (this branch):

Screenshot 2024-05-05 171148

Note the ~100x drop in instantiations. I'm unsure what the root cause of this is so if anyone could share any wisdom on how/why tsc treats this different to Extract it'd be really appreciated!

@typescript-bot
Copy link
Contributor

typescript-bot commented May 5, 2024

@awphi Thank you for submitting this PR! I see this is your first time submitting to DefinitelyTyped 👋 — I'm the local bot who will help you through the process of getting things through.

This is a live comment which I will keep updated.

1 package in this PR

Code Reviews

Because this is a widely-used package, a DT maintainer will need to review it before it can be merged.

You can test the changes of this PR in the Playground.

Status

  • ✅ No merge conflicts
  • ✅ Continuous integration tests have passed
  • 🕐 Only a DT maintainer can approve changes without tests

Once every item on this list is checked, I'll ask you for permission to merge and publish the changes.

Inactive

This PR has been inactive for 13 days — please try to get reviewers!


Diagnostic Information: What the bot saw about this PR
{
  "type": "info",
  "now": "-",
  "pr_number": 69522,
  "author": "awphi",
  "headCommitOid": "f3796fa58a5c6b8f5452dc7bede3bc8d8dd84ebb",
  "mergeBaseOid": "5650c99ad5376096f2f4ca0b257b78b231092296",
  "lastPushDate": "2024-05-05T17:07:26.000Z",
  "lastActivityDate": "2024-05-06T22:55:42.000Z",
  "hasMergeConflict": false,
  "isFirstContribution": true,
  "tooManyFiles": false,
  "hugeChange": false,
  "popularityLevel": "Critical",
  "pkgInfo": [
    {
      "name": "babel__traverse",
      "kind": "edit",
      "files": [
        {
          "path": "types/babel__traverse/index.d.ts",
          "kind": "definition"
        }
      ],
      "owners": [
        "yortus",
        "marvinhagemeister",
        "rpetrich",
        "mgroenhoff",
        "dlgrit",
        "ifiokjr",
        "ExE-Boss",
        "danez"
      ],
      "addedOwners": [],
      "deletedOwners": [],
      "popularityLevel": "Critical"
    }
  ],
  "reviews": [],
  "mainBotCommentID": 2094880628,
  "ciResult": "pass"
}

@typescript-bot typescript-bot added Critical package Untested Change This PR does not touch tests labels May 5, 2024
@typescript-bot
Copy link
Contributor

Hey @awphi,

😒 Your PR doesn't modify any tests, so it's hard to know what's being fixed, and your changes might regress in the future. Please consider adding tests to cover the change you're making. Including tests allows this PR to be merged by yourself and the owners of this module.

This can potentially save days of time for you!

@typescript-bot typescript-bot added this to Waiting for Code Reviews in New Pull Request Status Board May 5, 2024
@typescript-bot
Copy link
Contributor

🔔 @yortus @marvinhagemeister @rpetrich @mgroenhoff @dlgrit @ifiokjr @ExE-Boss @danez — please review this PR in the next few days. Be sure to explicitly select Approve or Request Changes in the GitHub UI so I know what's going on.

@typescript-bot typescript-bot moved this from Waiting for Code Reviews to Needs Maintainer Review in New Pull Request Status Board May 5, 2024
@danez
Copy link
Contributor

danez commented May 5, 2024

That sounds amazing. I'm not versed enough why this happens.

Will check this in one of my projects.

[Type in Node["type"]]?: VisitNode<S, Extract<Node, { type: Type }>>;
[N in Node as N["type"]]?: VisitNode<S, N extends { type: N["type"] } ? N : never>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can think of a couple of reasons; one is just that you've switched (I think?) the mapped type to be homomorphic by specifically doing N in Node as N["type"]; this may actually end up being a behavior change just due to how these mappings work...

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No obvious outward differences jumped out at me between the two kinds of mapped types at the bottom of this little playground (albeit it's hard to see the whole picture) besides the aforementioned speed. Can you think of what the downstream behavioural changes may be? If so I'm happy to investigate a bit further.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest and say that I'm not an expert here; @weswigham would probably know how to better reason about this as I'm more or less parroting off of others 😄

@typescript-bot
Copy link
Contributor

Re-ping @yortus, @marvinhagemeister, @rpetrich, @mgroenhoff, @dlgrit, @ifiokjr, @ExE-Boss, @danez:

This PR has been out for over a week, yet I haven't seen any reviews.

Could someone please give it some attention? Thanks!

@typescript-bot typescript-bot added the Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. label May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Critical package Unreviewed No one showed up to review this PR, so it'll be reviewed by a DT maintainer. Untested Change This PR does not touch tests
Projects
New Pull Request Status Board
Needs Maintainer Review
Development

Successfully merging this pull request may close these issues.

None yet

4 participants