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
base: master
Are you sure you want to change the base?
Conversation
@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 PRCode ReviewsBecause 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
Once every item on this list is checked, I'll ask you for permission to merge and publish the changes. InactiveThis 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"
} |
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! |
🔔 @yortus @marvinhagemeister @rpetrich @mgroenhoff @dlgrit @ifiokjr @ExE-Boss @danez — please review this PR in the next few days. Be sure to explicitly select |
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>; |
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 😄
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! |
Please fill in this template.
pnpm test <package to test>
.package.json
- N/A.Minimal repro of noticeable performance drain in this StackBlitz with this MR change applied as patch.
Before (prod):
After (this branch):
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!